emolog

脳内メモです。

【Flutter】formとsubmitボタンを定義する

Flutterでフォームとsubmitとボタンを作成したかったのでメモです。

  Widget build(BuildContext context) {
    final roomNameFocusNode = FocusNode();
    final formState = GlobalKey<FormState>();

    return
      Form(
        key: formState,
        child: Column(
          children: [
            TextFormField(
              // 画面遷移時にformにオートフォーカスする
              autofocus: true,
              // キーボードでのEnter時の処理
              onFieldSubmitted: (value) {
                print(value);
              }, // 追加
              onSaved: (value) {
              },
            ),
            FlatButton(
              child: Text('Save'),
              color: Colors.grey,
              // submitした時の処理
              onPressed: () {
              },
            ),
          ],
        ),
      );
  }