使用键盘时,模式安全区被忽略。在此示例中,您可以通过单击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) {},
),
),
),
),
),
),
),
);
最佳答案
我会在Padding
中使用SafeArea
小部件而不是BotttomModalSheet
,尤其是因为您不处理屏幕顶部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) {},
),
),
),
),
如果这不是您想要的,请告诉我
关于flutter - 键盘取消Modal中的SafeArea,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61109899/