【问题标题】:WillPopScope does not work from another widgetWillPopScope 不适用于其他小部件
【发布时间】:2021-10-03 16:52:04
【问题描述】:

我的 Flutter 应用中有多个小部件。如果我单击另一个小部件,Widget build(BuildContext context) 顶部定义的 onWillPopScope 方法将不起作用。你能给我建议如何解决它吗?谢谢

见以下代码:

 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'));

}

【问题讨论】:

    标签: flutter dart widget textfield back-button-control


    【解决方案1】:

    请您提供更多背景信息吗?

    正如documentations 所说:

    WillPopScope 类

    注册回调以否决用户尝试关闭封闭的 ModalRoute。

    这意味着它将在pop 操作上被调用。可以通过单击返回箭头从 android 导航中调用它,或者通过从边缘左侧向右滑动来调用 iOS。以及您通过Navigator 调用的所有其他pop 方法。所以它与点击 Widget 没有关系。

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 2021-01-09
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多