Forms 在Flatter TextFormField中输入数据时,键盘不断消失
我有一个简单的登录屏幕,有两个Forms 在Flatter TextFormField中输入数据时,键盘不断消失,forms,flutter,flutter-widget,Forms,Flutter,Flutter Widget,我有一个简单的登录屏幕,有两个TextFormField用于电子邮件和密码。当我试图在这些文本框中输入文本时,键盘会立即出现,每次我集中精力输入数据时,键盘就会消失 class LogInPage extends StatefulWidget { final String title; LogInPage({Key key, this.title}) : super(key: key); @override _LogInPageState createState() =>
TextFormField
用于电子邮件和密码。当我试图在这些文本框中输入文本时,键盘会立即出现,每次我集中精力输入数据时,键盘就会消失
class LogInPage extends StatefulWidget {
final String title;
LogInPage({Key key, this.title}) : super(key: key);
@override
_LogInPageState createState() => new _LogInPageState();
}
class _LogInPageState extends State<LogInPage> {
static final formKey = new GlobalKey<FormState>();
String _email;
String _password;
Widget padded({Widget child}) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: child,
);
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(children: [
Card(
child:
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
Container(
padding: const EdgeInsets.all(16.0),
child: Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
padded(
child: TextFormField(
key: Key('email'),
decoration: InputDecoration(labelText: 'Email'),
autocorrect: false,
validator: (val) => val.isEmpty
? 'Email can\'t be empty.'
: null,
onSaved: (val) => _email = val,
)),
padded(
child: TextFormField(
key: Key('password'),
decoration:
InputDecoration(labelText: 'Password'),
obscureText: true,
autocorrect: false,
validator: (val) => val.isEmpty
? 'Password can\'t be empty.'
: null,
onSaved: (val) => _password = val,
)),
]))),
])),
])));
}
}
首先清理代码并重新构建,然后使用真实设备执行测试
static GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
static GlobalKey\u formKey=new GlobalKey();
您是否尝试清理并重新运行到真实设备中,当我尝试使用我的设备时,此代码运行良好,不会消失。我正在Pixel 3 XL设备上运行。同样的行为。你们试过emulator吗?是的,我只试过ios模拟器和真正的安卓设备。@bianca我也很满意。我认为您需要清理构建。感谢您帮助我调试此问题。我想这是我给LogInPage打电话的方式。请参考上面编辑部分中的代码。
static GlobalKey<FormState> _formKey = new GlobalKey<FormState>();