繁体   English   中英

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

[英]Flutter: Text diappears from TextFormField after clicking on checkmark/enter button in android emulator

我有这个 flutter 移动应用程序,我已经用了几天了。

我已经设置了登录/注册页面和虚拟主页并添加了身份验证支持。

然后我注意到,当我单击 android 模拟器实例上的复选标记/输入按钮时,我的一些文本表单字段会自动删除其中的文本。

但是每当我点击其他表单域或只是空白屏幕时,文本都不会消失。

编辑:它从我所有的文本表单字段中删除文本。

这是其中一个字段的代码:

    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)),
      ),
    );```  

在构建时(构建方法)将 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM