##问题如下题
我们在使用flutter的TextField文本输入框组件的时候,正常展示的时候是没有问题的,但是如果获取到焦点后输入软键盘d出来就会出现类似:A RenderFlex overflowed by XX pixels on the bottom.,
屏幕下面有一条黄黑线交替出现,这是是因为输入框d出的时候界面压缩了,组件展示不下,超出屏幕,所有提示这个,这个问题类似Android里面界面内容太多,使用LinearLayout等布局,展示不下,所有我们需要在TextField外面套一层SingleChildScrollView,可以滚动组件,这个类似Scrollview可以滑动展示全部内容(列表请使用ListView),原来代码是这样:
State的build返回view,其他省略:
return new Scaffold(
appBar: new AppBar(
title: new Text("充值"),
),
body: new Container(
margin: EdgeInsets.fromLTRB(10, 10, 0, 0),
width: double.infinity,
height: double.infinity,
color: Colors.white,
child: new Column(
children;[Container(
margin: EdgeInsets.only(top: 15),
child: Column(
children: [
Container(
child: Text('其他充值金额'),
alignment: Alignment.centerLeft,
),
Container(
margin: EdgeInsets.only(top: 5, right: 5),
height: 60,
decoration: BoxDecoration(
border:
Border.all(color: Colors.black, width: 1),
borderRadius:
BorderRadius.all(Radius.circular(5)),
// color: Colors.orange
),
alignment: Alignment.center,
child: Container(
margin: EdgeInsets.only(left: 5),
child: TextField(
decoration: InputDecoration.collapsed(
hintText: '输入1-10000元',
),
keyboardType: TextInputType.number,
inputFormatters: [LengthLimitingTextInputFormatter(4)],
style: TextStyle(color: Colors.grey),
onChanged: (v) => {goRechargeInput(v)},
),
)),
],
),
),]
)
修改后代码如下:
return new Scaffold(
appBar: new AppBar(
title: new Text("充值"),
),
body: new Container(
margin: EdgeInsets.fromLTRB(10, 10, 0, 0),
width: double.infinity,
height: double.infinity,
color: Colors.white,
child:new **SingleChildScrollView**(
child: Column(
children;[
Container(
margin: EdgeInsets.only(top: 15),
child: Column(
children: [
Container(
child: Text('其他充值金额'),
alignment: Alignment.centerLeft,
),
Container(
margin: EdgeInsets.only(top: 5, right: 5),
height: 60,
decoration: BoxDecoration(
border:
Border.all(color: Colors.black, width: 1),
borderRadius:
BorderRadius.all(Radius.circular(5)),
// color: Colors.orange
),
alignment: Alignment.center,
child: Container(
margin: EdgeInsets.only(left: 5),
child: TextField(
decoration: InputDecoration.collapsed(
hintText: '输入1-10000元',
),
keyboardType: TextInputType.number,
inputFormatters: [LengthLimitingTextInputFormatter(4)],
style: TextStyle(color: Colors.grey),
onChanged: (v) => {goRechargeInput(v)},
),
)),
],
),
),]
))
软件他d出是这样的:
大功告成!这个其实思路是一样的,一天解决一个问题,1年后你就少365个烦恼!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)