在Flutter中完成最大字符后,如何将焦点更改到其他文本字段?

问题描述 投票:0回答:1

完成最大字符后如何在不按Flutter的同时按下next / done的情况下将焦点切换到其他节点?如何使用“焦点”节点将控件传递给其他TextField。我想将控件传递到每个文本字段的4个字符之后的下一个文本字段。

Widget serailKey1() {
        return TextField(
            controller: controller_key1,
            focusNode: _serialKeyFN1,
            textAlign: TextAlign.center,
            keyboardType: TextInputType.text,
            textCapitalization: TextCapitalization.characters,
            style: textStyle,
            maxLength: 4,

            decoration: new InputDecoration(

              counterText: "",
              border: new OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  const Radius.circular(0.0),
                ),
              ),
          ),
          onEditingComplete: ()=> FocusScope.of(context).requestFocus(_serialKeyFN2),

        );
      }

      Widget serailKey2() {
        return TextField(
            controller: controller_key2,
            focusNode: _serialKeyFN2,
            textAlign: TextAlign.center,
            keyboardType: TextInputType.text,
            style: textStyle,
            textCapitalization: TextCapitalization.characters,
            maxLength: 4,
            decoration: new InputDecoration(
              counterText: "",
              border: new OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  const Radius.circular(0.0),
                ),
              ),

            ),
          onEditingComplete: ()=> FocusScope.of(context).requestFocus(_serialKeyFN3),

        );
      } 
flutter flutter-layout
1个回答
0
投票

对我来说这很好:

    FocusNode fNode = FocusNode();
    ...
    TextField(onChanged: (value){ 
      if(value.length == 4) 
        FocusScope.of(context).requestFocus(fNode);
    }),
    TextField(focusNode: fNode),
© www.soinside.com 2019 - 2024. All rights reserved.