flutter - 如何在颤动中在键盘和焦点文本字段之间添加空格?
问题描述
我在滚动时遇到了这个问题,当我关注文本字段时,红色容器覆盖了我想写的文本字段。如何控制滚动,使 Textfield 显示在红色容器上方?
我想在 keabord 上方显示红色 Container,当用户在 Textfield 中写入时,我想激活 nect 按钮。
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
FocusNode _focusNode = new FocusNode();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Focus Example"),
),
body: Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 9, // 90% of space => (6/(6 + 4))
child: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints:
BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
new Container(
height: 800.0,
color: Colors.blue.shade200),
new TextFormField(
focusNode: _focusNode,
decoration: new InputDecoration(
hintText: 'Focus me!',
),
),
new Container(
height: 800.0,
color: Colors.blue.shade200),
],
),
),
),
);
},
)),
Expanded(
flex: 1, // 10% of space
child: Container(
color: Colors.purple,
alignment: Alignment.center,
),
),
],
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
height: 60,
color: Colors.red,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Text("Back",
style:
TextStyle(color: Colors.white, fontSize: 18.0)),
onTap: () {}),
Container(
width: 40,
height: 40,
child: FlatButton(
textColor: Colors.white,
disabledColor: Colors.grey,
disabledTextColor: Colors.white70,
padding: EdgeInsets.only(top: 0.0, bottom: 0.0),
splashColor: Colors.white,
onPressed: () {},
child: Icon(
Icons.navigate_next,
size: 35,
),
),
)
],
),
),
)
],
));
}
}
解决方案
我可以给你一个想法。试试这样的,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.9 - 60,
child: Row( ..... ), // Include SingleChildScrollView too
),
Container(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
height: 60,
child: Row( ... )
)
]
希望能解决您的问题。
推荐阅读
- sql-server - 使用 select 创建列并根据条件向其中添加数据?
- python - 无法在 Python 中打印
- .net-core - 使用 AWS 本地配置文件进行开发的 AWS .NET Core Worker 服务正在尝试从实例配置文件访问 IAM 凭证?
- python - 围绕一个点绘制/绘制一个具有一定半径的圆(matplotlib)
- r - 绘制 R 中逻辑回归的“model.averaging”对象的交互
- pulumi - 如何使用 pulumi 为 aws fargate 设置容器端口和负载均衡器?
- typescript - 如何避免手动复制 TypeScript 接口中的类型文档
- python - 如何从两个父类调用“覆盖”方法?
- python - 为什么 Beautifulsoup.find() 没有给出具体结果?
- embedded - glibc 可以在裸机或 RTOS 平台上运行吗?