flutter - WillPopScope 不适用于其他小部件
问题描述
我的颤振应用程序中有多个小部件。如果我单击另一个小部件,则在顶部定义的 onWillPopScope 方法Widget build(BuildContext context)
不起作用。你能给我建议如何解决它吗?谢谢
见下面的代码:
ExpansionTile(
initiallyExpanded: false,
title:
Text('Solution', style: basicAlertBlack),
children: <Widget>[
Container(
color: Colors.amber.shade50,
height:
MediaQuery
.of(context)
.size
.height /
7,
child: _solutionTextField(),
)
],
),
第二个小部件的代码:
Widget _solutionTextField() {
return TextField(
focusNode: myFocusNode,
keyboardType: TextInputType.multiline,
maxLines: null,
style: solution,
controller: solutionController,
decoration: new InputDecoration(
contentPadding: EdgeInsets.all(8),
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: 'Enter a solution'));
}
解决方案
你能提供更多的上下文吗?
正如文件所说:
WillPopScope 类
注册回调以否决用户尝试关闭封闭的 ModalRoute。
这意味着它将被调用pop
。可以通过单击返回箭头从 android 导航中调用它,或者通过从边缘左侧向右滑动来调用 iOS。pop
以及您通过调用的所有其他方法Navigator
。所以它与点击 Widget 没有关系。
推荐阅读
- shopware - 我如何以 Shopware 6 的形式上传拖车图像
- java - 使用 JScrollPane 的正确方法是什么?
- java - 使用 java grpc 在 ServerInterceptor 中验证请求的方法
- python - 在 Python 中使用消息框时出现错误
- asp.net-core - 避免剃刀页面中代码重复的最简单方法
- database - Laravel 中的雄辩关系(7)
- node.js - 使用 Express/node 全局监听
- python - 如何在 Flutter 中集成自定义 Python 人脸识别模型?
- javascript - 我想在我的反应应用程序中更改一本书的状态,但它会更改整个数组的状态
- c# - 按 Group Wise 找出平均值,然后将列转换为行