Flutter 颤振光标同时出现在两个字段中

Flutter 颤振光标同时出现在两个字段中,flutter,Flutter,我对flifter textformfield有问题。正如我在标题中所说,我的应用程序在两个textformfield中显示光标。当我点击上一个文本字段时,它会出现。我用的是真实的手机进行测试,而不是在模拟器中试用。谢谢你的帮助。 以下是我的应用程序中的图像: 表单( 键:_formKey, 子:列( 儿童:[ 大小盒子( 身高:20.0, ), TextFormField( 装饰:输入装饰(标签文本:“电子邮件”), focusNode:_emailFocus, 已提交:(任期){ _pas

我对flifter textformfield有问题。正如我在标题中所说,我的应用程序在两个textformfield中显示光标。当我点击上一个文本字段时,它会出现。我用的是真实的手机进行测试,而不是在模拟器中试用。谢谢你的帮助。 以下是我的应用程序中的图像:

表单(
键:_formKey,
子:列(
儿童:[
大小盒子(
身高:20.0,
),
TextFormField(
装饰:输入装饰(标签文本:“电子邮件”),
focusNode:_emailFocus,
已提交:(任期){
_passwordFocus.nextFocus();
_现场焦点更改(
上下文,_emailFocus,_passwordFocus);
},
textInputAction:textInputAction.next,
验证程序:(值)=>
value.isEmpty?“输入电子邮件”:null,
一旦更改:(值){
设置状态(()=>email=value);
},
),
大小盒子(
身高:20.0,
),
TextFormField(
装饰:输入装饰(标签文本:“密码”),
验证器:(值)=>value.length<6
?'输入密码6个字符长'
:null,
蒙昧文字:对,
focusNode:_passwordFocus,
已提交:(任期){
_passwordFocus.unfocus();
_submitForm();
},
textInputAction:textInputAction.done,
一旦更改:(值){
设置状态(()=>密码=值);
},
),
大小盒子(
身高:20.0,
),
升起的按钮(
颜色:主题。背景。原色,
子项:文本(“登录”),
已按下:(){
_submitForm();
},
),
尺寸箱(高度:12.0),
文本(错误,
风格:
TextStyle(颜色:Colors.red,fontSize:14.0)),
],
)),

我从这个问题中找到了解决方案:

它和我的一样。我们犯了同样的错误。当我声明FocusNode全局时,它解决了这个问题

Form(
    key: _formKey,
    child: Column(
    children: <Widget>[
    SizedBox(
     height: 20.0,
    ),
    TextFormField(
     decoration: InputDecoration(labelText: 'Email'),
     focusNode: _emailFocus,
     onFieldSubmitted: (term) {
      _passwordFocus.nextFocus();
      _fieldFocusChange(
       context, _emailFocus, _passwordFocus);
      },
      textInputAction: TextInputAction.next,
      validator: (value) =>
       value.isEmpty ? 'Enter an email' : null,
      onChanged: (value) {
       setState(() => email = value);
      },
      ),
      SizedBox(
       height: 20.0,
      ),
      TextFormField(
        decoration: InputDecoration(labelText: 'Password'),
        validator: (value) => value.length < 6
        ? 'Enter an password 6+ chars long'
        : null,
        obscureText: true,
        focusNode: _passwordFocus,
        onFieldSubmitted: (term) {
        _passwordFocus.unfocus();
        _submitForm();
        },
        textInputAction: TextInputAction.done,
        onChanged: (value) {
         setState(() => password = value);
        },
        ),
        SizedBox(
         height: 20.0,
        ),
        RaisedButton(
         color: Theme.of(context).primaryColor,
         child: Text('Sign in'),
         onPressed: () {
          _submitForm();
         },
         ),
         SizedBox(height: 12.0),
         Text(error,
          style:
           TextStyle(color: Colors.red, fontSize: 14.0)),
          ],
)),