[英]Flutter: Text diappears from TextFormField after clicking on checkmark/enter button in android emulator
I have this flutter mobile application that I've been working on for a couple of days now..我有这个 flutter 移动应用程序,我已经用了几天了。
I'v set up the login/register page and a dummy homepage and added authentication support.我已经设置了登录/注册页面和虚拟主页并添加了身份验证支持。
I then noticed that some of my textformfields automatically delete the text inside when I click the checmark/enter button on the android emulator instance.然后我注意到,当我单击 android 模拟器实例上的复选标记/输入按钮时,我的一些文本表单字段会自动删除其中的文本。
but the the text doesnt disapear whenever I click on anything else like another formfield or just the blank screen.但是每当我点击其他表单域或只是空白屏幕时,文本都不会消失。
edit: it deletes the text from all my text form fields.编辑:它从我所有的文本表单字段中删除文本。
here is the code for one of the fields:这是其中一个字段的代码:
final name_label = Text(
' First Name:',
style: TextStyle(color: Colors.black54),
);
final name = TextFormField(
validator: (val) {
if (val == '') {
return 'This Field Cannot Be Empty';
} else if (val!.length > 20) {
return "This Field Can't Have more than 20 characters";
} else {
return null;
}
},
onFieldSubmitted: (value) {
first_name_controller.text = value;
},
controller: first_name_controller,
keyboardType: TextInputType.name,
autofocus: false,
decoration: InputDecoration(
hintText: 'Joe',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)),
),
);```
made TextEditingController instances into class properties instead of instances at build time (build method).在构建时(构建方法)将 TextEditingController 实例制作成 class 属性而不是实例。
class _LoginPageState extends State<LoginPage> {
@override
final AuthService _login_checker = AuthService();
final _formkey = GlobalKey<FormState>();
final login_email_controller = TextEditingController();
final login_password_controller = TextEditingController();
Widget build(BuildContext context) {
final logo = Hero(
tag: 'hero',
child: CircleAvatar(
backgroundColor: Color.fromARGB(0, 180, 32, 32),
radius: 48.0,
child: Image.asset(
'lib/images/png-clipart-hamburger-button-computer-icons-marmon-keystone-canada-menu-red-sea.png'),
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.