Flutter 颤振:向上移动对话框为软键盘腾出空间?
有没有办法将对话框(在我的例子中是Flutter 颤振:向上移动对话框为软键盘腾出空间?,flutter,Flutter,有没有办法将对话框(在我的例子中是AlertDialog)向上移动,以便在软键盘可见时为其腾出空间 这是一个已知的错误: 如果有帮助的话,这个bug中有一个解决方法。试试这个 return SingleChildScrollView( padding: EdgeInsets.only(top: yourFocus.hasFocus ? MediaQuery.of(context).size.height / 2
AlertDialog
)向上移动,以便在软键盘可见时为其腾出空间
这是一个已知的错误:
如果有帮助的话,这个bug中有一个解决方法。试试这个
return SingleChildScrollView(
padding: EdgeInsets.only(top: yourFocus.hasFocus ?
MediaQuery.of(context).size.height / 2 - 250 // adjust values according to your need
: MediaQuery.of(context).size.height / 2 - 130),// adjust values according to your need
child: AlertDialog(
title: Text("your Alert header text"),
content: TextField(
focusNode: yourFocus,
controller: yourTextController,
decoration: InputDecoration.collapsed(
hintText: "your hint text."),
),
actions: <Widget>[
FlatButton(
child: Text("Your button Title"),
onPressed: () {
yourFunction();
})
]));
返回SingleChildScrollView(
填充:EdgeInsets.only(顶部:yourFocus.hasFocus?
MediaQuery.of(context).size.height/2-250//根据需要调整值
:MediaQuery.of(context.size.height/2-130),//根据需要调整值
子:警报对话框(
标题:文本(“您的警报标题文本”),
内容:TextField(
focusNode:yourFocus,
控制器:你的文本控制器,
装饰:输入装饰(
hintText:“您的提示文本。”),
),
行动:[
扁平按钮(
子:文本(“您的按钮标题”),
已按下:(){
yourFunction();
})
]));
添加此页边距页边距:MediaQuery.of(context).viewsinsets,
,它在自定义警报对话框中对我有效。这是我的答案:
用填充小部件包装对话框。
然后给财产
填充:仅限边缘设置(
底部:MediaQuery.of(context.viewInsets.bottom)
填充(
填充:仅限边缘设置(
底部:MediaQuery.of(context.viewInsets.bottom),
儿童:中心(
儿童:材料(
颜色:颜色,白色,
子:ScaleTransition(
缩放:缩放图像,
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
容器(
裕度:所有边缘集(20.0),
填充:所有边缘设置(15.0),
装饰:造型装饰(
颜色:颜色。透明,
形状:圆形矩形边框(
边界半径:边界半径。圆形(15.0)),
子:列(
儿童:[
填充物(
填充:仅限常量边设置(
顶部:30.0,左侧:20.0,右侧:20.0),
子:文本(
“Masukkan密码akun anda”,
样式:TextStyle(颜色:Colors.black87,fontSize:16.0),
),
),
填充物(
填充:常量边集。全部(5),
子项:TextFormField(
装饰:输入装饰(
边框:大纲输入边框(
边界边(
宽度:1
),
边界半径:边界半径。圆形(5)
),
contentPadding:EdgeInsets.对称(水平:10,垂直:5)
),
键盘类型:TextInputType.text,
蒙昧文字:对,
样式:TextStyle(
尺寸:22,
字距:1
),
),
),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
填充物(
填充:常数边集全部(10.0),
孩子:ButtonTheme(
身高:35.0,
最小宽度:110.0,
孩子:升起按钮(
颜色:颜色。绿色,
形状:圆形矩形边框(
边界半径:边界半径。圆形(5.0)),
飞溅颜色:颜色。白色。带有Alpha(40),
子:文本(
“好的”,
textAlign:textAlign.center,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.bold,
字体大小:13.0),
),
已按下:(){
Navigator.pop(上下文);
widget.nextPage();
},
)),
),
填充物(
填充:仅限常量边设置(
左:20.0,右:10.0,顶部:10.0,底部:10.0),
孩子:ButtonTheme(
身高:35.0,
最小宽度:110.0,
孩子:升起按钮(
颜色:颜色。红色[700],
形状:圆形矩形边框(
边界半径:边界半径。圆形(5.0)),
颜色:颜色。白色。w
Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Center(
child: Material(
color: Colors.white,
child: ScaleTransition(
scale: scaleAnimation,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(15.0),
decoration: ShapeDecoration(
color: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0))),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: 30.0, left: 20.0, right: 20.0),
child: Text(
"Masukkan password akun anda",
style: TextStyle(color: Colors.black87, fontSize: 16.0),
),
),
Padding(
padding: const EdgeInsets.all(5),
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
width: 1
),
borderRadius: BorderRadius.circular(5)
),
contentPadding: EdgeInsets.symmetric(horizontal:10,vertical:5)
),
keyboardType: TextInputType.text,
obscureText: true,
style: TextStyle(
fontSize: 22,
letterSpacing: 1
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: ButtonTheme(
height: 35.0,
minWidth: 110.0,
child: RaisedButton(
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
splashColor: Colors.white.withAlpha(40),
child: Text(
'OK',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13.0),
),
onPressed: () {
Navigator.pop(context);
widget.nextPage();
},
)),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 10.0, top: 10.0, bottom: 10.0),
child: ButtonTheme(
height: 35.0,
minWidth: 110.0,
child: RaisedButton(
color: Colors.red[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
splashColor: Colors.white.withAlpha(40),
child: Text(
'Batal',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 13.0),
),
onPressed: () {
setState(() {
Navigator.pop(context);
});
},
))
),
],
)
],
)),
],
),
),
),
),
)