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

时间:2019-12-28 22:53:08

标签: flutter

我对flutter textformfield有问题。就像我在标题中说的那样,我的应用程序在两个textformfield中显示光标。当我点击上一个文本字段时,它会出现。我正在使用真实的手机进行测试,而不是在模拟器中尝试过。谢谢你的帮助。 这是我的应用中的图片: enter image description here

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)),
          ],
)),

1 个答案:

答案 0 :(得分:0)

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

Multiple cursor in form's TextFormField flutter

与我的相同。我们犯了同样的错误。当我全局声明FocusNode时,它可以解决问题。