我的Flutter应用程序中有一个文本字段,用户可以在其中输入他们的姓名。他们可以按“提交”。但是当名称太短时,我会显示一个对话框。
问题:当显示对话框时,键盘自动关闭,并且警报对话框从上方(当键盘仍处于 Activity 状态时)跳转到下方(当键盘不再处于 Activity 状态时,半秒后)。
showDialog(
context: context,
builder: (_) => new AlertDialog(
title: Text("Error"),
content:
Text("Name too short"),
));
显示AlertDialog时是否可以保持键盘处于 Activity 状态?
谢谢!
最佳答案
我不相信有一种方法可以做您想做的事,但我已经弄清楚了hack尝试一下,看看您的想法
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
onFieldSubmitted: (String value) async {
if (value.length < 3) {
return await showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("Error"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AbsorbPointer(
child: TextFormField(
cursorColor: Colors.white,
decoration: InputDecoration(
border: InputBorder.none,
hintText: " Name too short",
hintStyle: TextStyle(color: Colors.black),
),
autofocus: true,
),
),
],
),
),
);
}
},
)
],
),
),
关于flutter - 显示alertDialog时 flutter 键盘被关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61292620/