title: Flutter: onSaved method of TextFormField not storing values to variables
body: <p>I have a form which prompts the user to enter the address. The form is broken down into multiple TextFormField widgets which is defined in a file called <code>address_widget.dart</code>. These widgets are called from the file: <code>AddressPage.dart</code>. The form loads and gets validated properly but the values saved by the onSaved methods in <code>address_widget.dart</code> is not getting stored in the variables <code>city</code> and <code>address</code> in <code>AddressPage.dart</code>. When printing the variables <code>city</code> and <code>address</code>, null is printed. Is this the correct way to do it or am I missing something?</p>
  <p><em><strong>address_widget.dart</strong></em></p>
  <pre><code>Widget buildCity(city) {
      return TextFormField(
        style: TextStyle(
          fontFamily: 'Montserrat',
          fontSize: 2 * SizeConfig.textMultiplier,
        ),
        decoration: InputDecoration(
          labelText: 'City',
        ),
        validator: (String value) {
          if (value.isEmpty) {
            return 'This field is Required';
          }
        },
        onSaved: (String value) {
          city = value;
        },
      );
  }
  
  Widget buildAddress(address) {
      return TextFormField(
        style: TextStyle(
          fontFamily: 'Montserrat',
          fontSize: 2 * SizeConfig.textMultiplier,
        ),
        decoration: InputDecoration(
          labelText: 'Address',
        ),
        validator: (String value) {
          if (value.isEmpty) {
            return 'This field is Required';
          }
        },
        onSaved: (String value) {
          address = value;
        },
      );
  }
  </code></pre>
  <p><em><strong>AddressPage.dart</strong></em></p>
  <pre><code>import 'package:userproject/widgets/address_widget.dart';
  
  class AddressPage extends StatefulWidget {
    @override
    _AddressPageState createState() =&gt; _AddressPageState();
  }
  
  class _AddressPageState extends State&lt;AddressPage&gt; {
    
    final GlobalKey&lt;FormState&gt; _formKey = GlobalKey&lt;FormState&gt;();
    final GlobalKey&lt;ScaffoldState&gt; _scaffoldKey = GlobalKey&lt;ScaffoldState&gt;();
    String city;
    String address;  
    
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        key: _scaffoldKey,
        body: Form(
                 key: _formKey,
                 child: Column(
                        children: &lt;Widget&gt;[
                          Text(
                            'Enter your Address',
                            style: TextStyle(
                              fontFamily: 'Montserrat',
                              fontWeight: FontWeight.bold,
                            ),
                          buildCity(city),
                          buildAddress(address),
                          Row(
                            children: [
                              RaisedButton(
                                onPressed: () {
                                  if (!_formKey.currentState.validate()) {
                                         return;
                                   }
                                   _formKey.currentState.save(); 
  
                                  print(&quot;city - $city&quot;); // prints null
                                  print(&quot;address- $address&quot;); // prints null
                                },
                              ),
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
      }
  }
  </code></pre>
  <p>The code has been simplified for easy reference.</p>