flutter - 即使在显示键盘后如何使容器修复定位
问题描述
我已经玩了一段时间了,但无法正常工作。基本上我有底部导航栏,我想在底部导航栏的顶部固定定位的容器,即使显示键盘也会留在那里。到目前为止,无论我尝试什么,当调用键盘时,容器最终都会出现在键盘的顶部。到目前为止,这是我的代码。基本上我最后的希望是将它包装在 Stack 小部件中,但这没有用。
class HomeScreen extends StatefulWidget { static const String id = '/app'; final FirebaseUser user; HomeScreen({this.user});
@override _HomeScreenState createState() => _HomeScreenState(); }
class _HomeScreenState extends State<HomeScreen> { int _currentIndex
= 0; final List<Widget> _children = [Screen1(), Screen2()];
void bottomTabHandler(int index) {
setState(() {
_currentIndex = index;
}); }
@override Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _currentIndex,
onTap: bottomTabHandler,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.receipt),
title: Text('Option1'),
),
BottomNavigationBarItem(
icon: Icon(Icons.receipt),
title: Text('Option2'),
),
BottomNavigationBarItem(
icon: Icon(Icons.add), title: Text('Option3')),
],
),
appBar: AppBar(
centerTitle: true,
title: Text('XXX'),
automaticallyImplyLeading: false,
),
endDrawer: AppbarDrawer(),
body: Stack(
children: <Widget>[
_children[_currentIndex],
Positioned(
bottom: 0,
child: Container(
width: 250,
height: 100,
color: Colors.blue,
),
),
],
),
);
}
}
我在 screen1 有简单的 TextField 这就是我得到的
解决方案
如果您想确保在键盘出现时不调整小部件,您可以使用以下resizeToAvoidBottomInset
属性Scaffold
:
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
...
推荐阅读
- java - @Slf4j 找不到符号 LOG
- pine-script - 收益线,从输入值绘制一条线
- python - pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] 参数太少。预期为 9. (-3010) (SQLExecDirectW)')
- javascript - 屏幕调整大小时重置切换(多种样式)
- react-router - 如何使用 Apollo 和 React Router 避免嵌套路由/查询组件的请求瀑布?
- android - Android Mokito 测试室 DAO 类。在测试时从数据库中获取数据时获取空数组
- python-3.x - 计算每个 id 有多少行满足条件
- jquery - 根据表单输入显示嵌入式视频
- laravel - Lumen:BrowserSync 与 Laravel Mix
- ruby-on-rails - Rails activerecord 查询使用选择但返回集合