flutter - 使用 SingleChildScrollView() 解决键盘遮挡输入框的问题
程序员文章站
2022-05-30 11:54:16
...
写好了,感觉可好
点击输入框,输入内容时发现如下,键盘遮挡了输入框
使用 SingleChildScrollView 解决遮挡问题, 就是让它滚动起来
- 直接使用 SingleChildScrollView 包裹子元素
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFcccccc),
body: SingleChildScrollView(
child: Column(
children: [
Container(
height: 200,
color: Colors.black12,
child: Center(child: Text("顶部")),
),
SizedBox(height: 20),
Container(
height: 200,
margin: EdgeInsets.all(10),
width: double.infinity,
color: Colors.white,
child: Column(
children: [
Container(
height: 40,
width: 250,
margin: EdgeInsets.all(10),
child: TextField(
decoration: InputDecoration(
fillColor: Color(0xffcfcccc),
filled: true,
hintText: '请输入账号',
contentPadding: EdgeInsets.only(left: 20),
),
),
),
Container(
height: 40,
width: 250,
margin: EdgeInsets.all(10),
child: TextField(
decoration: InputDecoration(
fillColor: Color(0xfffdfccc),
filled: true,
hintText: '请输入密码',
contentPadding: EdgeInsets.only(left: 20),
),
),
)
],
),
),
],
),
),
);
}
下一篇: 读取三维TIFF