flutter キーボードに完了ボタンを設置する

https://github.com/diegoveloper/flutter_keyboard_actions
これを使うとできるらしい。サンプルコードはサンプルが多かったのでとりあえず最低限のコードを

f:id:yoppy0066:20190703210442p:plain:h320

// ☆importする
import 'package:keyboard_actions/keyboard_actions.dart';

class MainScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Hello")),
      // ☆ FormKeyboardActionsで囲む
      body: FormKeyboardActions(
        child: Content(),
      ),
    );
  }
}

class Content extends StatefulWidget {
  Content({Key key}) : super(key: key);

  @override
  _ContentState createState() => new _ContentState();
}

class _ContentState extends State<Content> {

  var _emailFocusNode = FocusNode();
  var _passwordFocusNode = FocusNode();

  @override
  void initState() {
   // ☆ focustNodeをactionsにセット
    FormKeyboardActions.setKeyboardActions(
      context,
      KeyboardActionsConfig(
      actions: [
        KeyboardAction(focusNode: _emailFocusNode),
        KeyboardAction(focusNode: _passwordFocusNode),
      ],
      )
    );
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          _emailFocusNode.unfocus();
          _passwordFocusNode.unfocus();
        },
        child: Container(
          color: Colors.white,
          child: Padding(
            child: Column(
              children: <Widget>[
                // ☆ focusNodeをセット
                TextField(focusNode: _emailFocusNode),
                TextField(focusNode: _passwordFocusNode),
              ],
            ),
          ),
        )
    );
  }
}

以上です