简体   繁体   English

Flutter:在 android 模拟器中单击复选标记/输入按钮后,TextFormField 中的文本消失

[英]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.

相关问题 在 flutter android 中单击 TextFormField 时未显示键盘 - Keyboard is not showing on clicking on TextFormField in flutter android 单击 flutter 中的 TextFormField 后键盘正在关闭 - Keyboard is closing after clicking on TextFormField in flutter 在Android模拟器上,我的按钮没有点击 - On Android emulator my button is not clicking 单击菜单按钮后,Android菜单未在模拟器中显示 - Android Menu not showing in emulator on clicking on Menu button 单击按钮后,Android按钮文本将更改为垂直 - Android Button text changes to vertical after clicking button 单击Android Studio中的按钮后,如何在TextView中显示输入的文本? - How to display inputted text in a TextView after clicking a button in Android studio? Flutter 使用 TextFormField 进行货币文本格式化 - Flutter money text formatting with TextFormField 在flutter中禁用粘贴并从textformfield中选择所有功能按钮 - Disable paste and select all function button from textformfield in flutter 在android每个listview项中单击后的Chage按钮文本 - Chage button text after clicking it in android each listview item Android Listview-单击后更改项目按钮文本 - Android Listview - Change Item Button Text After Clicking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM