Slide focus to TextField in Flutter

前端 未结 3 2029
感情败类
感情败类 2021-02-01 13:41

I have been learning flutter for last few days and I encountered a problem while developing my app. So I have a basic form containing all the basic input fields and after a user

相关标签:
3条回答
  • 2021-02-01 13:49
    var focusNode = FocusNode();
    var textField = TextField(focusNode: focusNode);
    
    FocusScope.of(context).requestFocus(focusNode);
    // or 
    focusNode.requestFocus();
    

    See also

    • https://docs.flutter.io/flutter/widgets/FocusNode-class.html
    • https://flutter.dev/docs/cookbook/forms/focus
    0 讨论(0)
  • 2021-02-01 13:55

    Use

    FocusScope.of(context).previousFocus();


    Column(
      children: [
        TextField(...), // 1st TextField
        TextField(...), // 2nd TextField
        RaisedButton(
          onPressed: () => FocusScope.of(context).previousFocus(), // This is what you need
          child: Text("Go back"),
        ),
      ],
    )
    
    0 讨论(0)
  • 2021-02-01 14:12
     TextField(
          autofocus: true,
    );
    
    0 讨论(0)
提交回复
热议问题