title: Retrieve data from a Form within an Alert Dialog in Flutter
body: <p>In order for my app's Alert Dialogs to be consistent, I have created a function that returns an <strong>Alert Dialog</strong>. The function does a bit of &quot;painting&quot;, to make it look the way I want, but its basic structure is:</p>
  <pre class="lang-dart prettyprint-override"><code>AlertDialog myAlertDialog({
    @required BuildContext context,
    @required Widget myContent,
    @required Function onAccept,}){
  
    return AlertDialog(
    content: Column(
        children = [
         myContent,
         FlatButton(child: Text(&quot;ok&quot;), onPressed: onAccept),
         FlatButton(child: Text(&quot;cancel&quot;), onPressed: Navigator.pop(context),
        ]
      )
    );
  }
  </code></pre>
  <p>In this particular occasion, I am sending a Form to the <code>myContent</code> parameter. I am currently stuck on how to retrieve the data from the form in <code>myContent</code> and pass it to the function <code>onAccept</code>.</p>
  <p>In case it might be helpful, the following is the basic structure of my form:</p>
  <pre class="lang-dart prettyprint-override"><code>class myForm extends StatefulWidget {
    @override
    _myFormState createState() =&gt; _myFormState();
  }
  
  class _myFormState extends State&lt;myForm&gt; {
  @override
    Widget build(BuildContext context) {
      return Form(
        key: _formKey,
        child: ListView(
          children: [
              TextFormField(onChanged: (val) {setState(() {var1 = val;});}, ... ), //Field 1
              TextFormField(onChanged: (val) {setState(() {var2 = val;});}, ... ), //Field 2
              //...
            ],
          ),
     );
   }
  }
  
  </code></pre>
  <p>Thanks!</p>
  <p><strong>EDIT</strong>
  I noticed the following might also be useful/needed in order for my current problem to be more clear:</p>
  <p>This is how I call the <code>AlertDialog</code> from the main widget.</p>
  <pre class="lang-dart prettyprint-override"><code>class MainWidget extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: FlatButton(
          child: Text(&quot;launch Alert Dialog&quot;,),
          onPressed: () {showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return _launchAlertDialog(context);
                          },
                        );},
        ),
      );
    }
  }
  
  AlertDialog _launchAlertDialog(BuildContext context){
     return myAlertDialog(
       context: context,
       content: myForm(), //Data is captured here
       onAccept: (){}, //But I need to use it here
     );
  }
  </code></pre>