flutter - modalBottomSheet 被键盘覆盖
问题描述
它写在这里
/// 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
它将自行调整大小并且确实会发生。但是当我把 aTextField
放在里面时,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,
),
);
}
}
如果这个问题很愚蠢,我很抱歉,但我不明白这一点。
解决方案
我仍然不知道原因可能是因为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()
推荐阅读
- javascript - 如何提高 fetch api JSON 下载速度或加载图标?
- amazon-web-services - 如果 EKS 工作程序节点位于私有子网中,则 ELB 服务中断
- python - Python:选择尖括号之间的文本
- c# - asp.net 实体框架“插入”语句与外键约束冲突
- javascript - 如何将脚本插入 Dojo html 文件?
- c# - 如何从数据库中获取数据列表中的特定 ID?
- plsql - 用于 varchar 处理的 PL/SQL 中的 NVL 与 NVL2
- html - Web Scraping:在找到关键字时需要帮助返回整段文本
- sql-server - Microsoft 从 SQLExpress nchar 查询 Excel 未返回
- parsing - 如何报告使用 anltr 定义的未定义语法的错误