Changing focus from one text field to the next in Flutter

前端 未结 4 1752
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 03:40

I have two textFormField widgets. Once the user has completed the first text field I would like to focus on the next textField. Is there a way to do

4条回答
  •  日久生厌
    2021-02-05 03:55

    Screenshot:


    No need to use FocusNode

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(),
        body: Column(
          children: [
            TextField(
              decoration: InputDecoration(hintText: 'First Name'),
              textInputAction: TextInputAction.next,
              onEditingComplete: () => FocusScope.of(context).nextFocus(),
            ),
            TextField(
              decoration: InputDecoration(hintText: 'Last Name'),
              textInputAction: TextInputAction.done,
              onSubmitted: (_) => FocusScope.of(context).unfocus(),
            ),
          ],
        ),
      );
    }
    

提交回复
热议问题