使用 phone 键盘时颤动,文本框被隐藏
Flutter when using phone keyboard, textbox gets hidden
我在使用 phone 键盘时遇到问题,妨碍了用户必须输入的文本框,因为用户看不到他在写什么,这是它的样子
这是没有键盘的屏幕
这是带键盘的屏幕
这是我当前的文本字段代码
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
有什么办法可以防止这种情况发生吗?
谢谢你的时间
编辑:这是我的页面代码,脚手架已经包装好
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
width: double.infinity,
height: double.infinity,
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
}),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('closealert')),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
}),
],
),
],
),
),
));
});
});
试试这个,
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
body: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraint.maxHeight,
),
child: IntrinsicHeight(
child: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: Translations.of(context)
.trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
},
),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(
Translations.of(context)
.trans('closealert'),
),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
},
),
],
),
],
),
),
),
),
);
},
),
),
);
},
);
},
);
我在使用 phone 键盘时遇到问题,妨碍了用户必须输入的文本框,因为用户看不到他在写什么,这是它的样子
这是没有键盘的屏幕
这是带键盘的屏幕
这是我当前的文本字段代码
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
有什么办法可以防止这种情况发生吗? 谢谢你的时间
编辑:这是我的页面代码,脚手架已经包装好
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
width: double.infinity,
height: double.infinity,
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
}),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('closealert')),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
}),
],
),
],
),
),
));
});
});
试试这个,
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
body: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraint.maxHeight,
),
child: IntrinsicHeight(
child: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: Translations.of(context)
.trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
},
),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(
Translations.of(context)
.trans('closealert'),
),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
},
),
],
),
],
),
),
),
),
);
},
),
),
);
},
);
},
);