【问题标题】:Keyboard cancel SafeArea in Modal键盘取消模态中的安全区域
【发布时间】:2020-07-21 09:48:13
【问题描述】:

当使用键盘时,模态中的安全区域被忽略。在此示例中,您可以通过单击 TextField 来查看模态移动。如何在模态中使用 SafeArea 并避免在激活键盘时移动模态?

Scaffold(
      resizeToAvoidBottomInset: false,
      body: SafeArea(
        child: Center(
          child: FlatButton(
            child: Text('open modal'),
            onPressed: () => showModalBottomSheet(
              isScrollControlled: true,
              context: context,
              builder: (context) => SafeArea( //< when safearea is removed the modal doesn't move
                child: Container(
                  height: 500,
                  child: TextField(
                    onChanged: (v) {},
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我会在BotttomModalSheet 中使用Padding 小部件而不是SafeArea,尤其是因为您不处理屏幕顶部SafeArea 只不过是首先检查this 的填充小部件而已出去。

    showModalBottomSheet(
                  isScrollControlled: true,
                  context: context,
                  builder: (context) => Padding(
                    padding: const EdgeInsets.all(16),
                    //< when safearea is removed the modal doesn't move
                    child: Container(
                      height: 500,
                      child: TextField(
                        onChanged: (v) {},
                      ),
                    ),
                  ),
                ),
    

    如果这不是你要找的,请告诉我

    【讨论】:

    • 是的.. 我想这将是唯一的选择
    猜你喜欢
    • 2018-01-06
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 2011-06-29
    • 2019-04-13
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多