title: Receive Response from pop navigator in Flutter
body: <p>Here is a simple example of code that navigator push for a form called. and pop for an answer.
  my goal is to make a pop of an object, not a string, but keeping it that simple still doesn't work.</p>
  
  <p>main.dart:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  import 'answer.dart';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      final appTitle = 'Form Validation Demo';
  
      return MaterialApp(
        title: appTitle,
        home: Scaffold(
          appBar: AppBar(
            title: Text(appTitle),
          ),
          body: ShowData(),
        ),
      );
    }
  }
  
  // Create a Form widget.
  class MyCustomForm extends StatefulWidget {
    @override
    MyCustomFormState createState() {
      return MyCustomFormState();
    }
  }
  
  // Create a corresponding State class.
  // This class holds data related to the form.
  class MyCustomFormState extends State&lt;MyCustomForm&gt; {
    // Create a global key that uniquely identifies the Form widget
    // and allows validation of the form.
    //
    // Note: This is a GlobalKey&lt;FormState&gt;,
    // not a GlobalKey&lt;MyCustomFormState&gt;.
    final _formKey = GlobalKey&lt;FormState&gt;();
    final myController = TextEditingController();
    String stateData;
    @override
    void dispose() {
      // Clean up the controller when the widget is disposed.
      myController.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      // Build a Form widget using the _formKey created above.
      return Scaffold(
        body: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: &lt;Widget&gt;[
              TextFormField(
                controller: myController,
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter some text';
                  }
                  return null;
                },
                onSaved: (value){
                  stateData = value;
                },
              ),
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 16.0),
                child: RaisedButton(
                  onPressed: () {
                    // Validate returns true if the form is valid, or false
                    // otherwise.
                    if (_formKey.currentState.validate()) {
                      _formKey.currentState.save();
                      // If the form is valid, display a Snackbar.
                      Navigator.pop(context,stateData);
  //                  Scaffold.of(context)
  //                      .showSnackBar(SnackBar(content: Text(myController.text)));
  //                    myController.text = 'look at me';
                    }
                  },
                  child: Text('Submit'),
                ),
              ),
            ],
          ),
        ),
      );
    }
  </code></pre>
  
  <p>}</p>
  
  <p>answer.dart:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  import 'main.dart';
  
  class ShowData extends StatefulWidget {
  
    @override
    _ShowDataState createState() =&gt; _ShowDataState();
  }
  
  class _ShowDataState extends State&lt;ShowData&gt; {
    String data = 'start';
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          floatingActionButton: FloatingActionButton(onPressed: (){
            String holder =  getFormData(context);
            setState(() {
              data = holder;
            });
          },
          elevation: 4,
  
          ),
          body:Text(data,style: TextStyle(fontSize: 80),));
    }
  
    String getFormData(BuildContext context) {
      final Future&lt;String&gt; answer =  Navigator.push(context,MaterialPageRoute(builder: (context)=&gt;MyCustomForm()));
      answer.then((String value) {
          return value != null? value: 'empty';
        }
      );
    }
  }
  </code></pre>
  
  <p>when returning from the form error message is :</p>
  
  <blockquote>
    <p>'package:flutter/src/widgets/text.dart': Failed assertion: line ...
    pos... 'data!=null': A non-null String must be provided to a Text
    widget.</p>
  </blockquote>