它写成here那
/// The scaffold will expand to fill the available space. That usually
/// means that it will occupy its entire window or device screen. When
/// the device's keyboard appears the Scaffold's ancestor [MediaQuery]
/// widget's [MediaQueryData.viewInsets] changes and the Scaffold will
/// be rebuilt. By default the scaffold's [body] is resized to make
/// room for the keyboard.
因此,如果底部有一个TextField,则Scaffold
会自动调整大小,并且确实会发生。但是,当我将TextField
放在modalBottomSheet
内时,它不会被键盘推上去。键盘与modalBottomSheet
(与TextField
重叠)。如果Scaffold
本身的大小得到了调整,modalBottomSheet
将如何保持原样? resizeToAvoidBottomInset
对modalBottomSheet
没有影响。
这是示例代码。
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
showModalBottomSheet(
context: context, builder: (context) => ShowSheet());
},
),
);
}
}
class ShowSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 200,
child: TextField(
autofocus: true,
),
);
}
}
如果这个问题愚蠢,我深表歉意,但我不明白。
答案 0 :(得分:0)
我仍然不知道原因可能是因为modalBottomSheet
正在使用PopupRoute
,所以不确定这是一条不同的路线。无论如何,在这里我找到了我只需要放一些底部viewInsets填充的解决方案。
Widget build(BuildContext context) {
return Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
color: Colors.blue,
height: 200,
child: TextField(
autofocus: true,
),
),
);
}
我还需要将isScrollControlled: true,
中的showModalBottomSheet()
设置为