본문 바로가기
Flutter/Flutter FAQ

Flutter에서 다음 TextField로 포커스를 이동하는 방법은 무엇인가요?, How to shift focus to the next TextField in Flutter?

by 베타코드 2023. 5. 28.
반응형

질문


저는 플러터를 처음 사용합니다.

Form, TextFormField 위젯을 사용하여 여러 텍스트 입력란이있는 양식을 작성하고 있습니다. 나타나는 키보드에서는 "다음" (다음 필드로 포커스를 이동해야 함) 필드 작업이 아니라 "완료" 작업 (키보드를 숨기는 작업)이 표시되지 않습니다.

공식 문서에서 힌트를 찾아보았지만 직접적으로 할 수있는 것은 없었습니다. 나는 FocusNode (cookbook, api doc)에 도달했습니다. 이것은 앱에서 버튼이나 기타 작업을 사용하여 포커스를 이동시키는 메커니즘을 제공하지만 키보드에서 작동하도록하고 싶습니다.


답변


Screenshot:

enter image description here


Just use:

textInputAction: TextInputAction.next: To move the cursor to the next field.

textInputAction: TextInputAction.done: To close the keyboard.

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: <Widget>[
        TextField(
          decoration: InputDecoration(hintText: 'TextField A'),
          textInputAction: TextInputAction.next, // Moves focus to next.
        ),
        TextField(
          decoration: InputDecoration(hintText: 'TextField B'),
          textInputAction: TextInputAction.next, // Moves focus to next.
        ),
        TextField(
          decoration: InputDecoration(hintText: 'TextField C'),
          textInputAction: TextInputAction.done, // Hides the keyboard.
        ),
      ],
    ),
  );
}
반응형

댓글