content: import 'package:flutter/material.dart';
  
  void main() => runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: FormSamplePage(),
      );
    }
  }
  
  class FormSamplePage extends StatelessWidget {
    // (1) これが必ず必要
    final _formKey = GlobalKey<FormState>();
    final _scaffoldKey = GlobalKey<ScaffoldState>();
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: const Text('Sample'),
        ),
        body: Form(
          key: _formKey,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                TextFormField(
                  decoration: const InputDecoration(
                    border: OutlineInputBorder(),
                    filled: true,
                    icon: Icon(Icons.person),
                    hintText: '名前を入力してください',
                    labelText: '名前',
                  ),
                  validator: (value) {
                    if (value.isEmpty) {
                      return '必須です。';
                    }
                    return null;
                  },
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 16.0),
                  child: RaisedButton(
                    onPressed: () {
                      // (2) ここでvalidateを呼ぶ
                      if (_formKey.currentState.validate()) {
                        _scaffoldKey.currentState.showSnackBar(const SnackBar(
                          content: Text('Processing Data'),
                        ));
                      }
                    },
                    child: const Text('Submit'),
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  