title: How to update the button text in a flutter alert box
body: <p>I have an alert box in flutter that prompts the user for a name and date. The name is a simple TextField and the date is entered by clicking a button to open a date picker. Initially the button has the current date as the text.I would like this to be updated by the selected date, but can't get it to happen. It does get updated when I go back the to text input though.</p>
  
  <p>Thanks for any help</p>
  
  <p>My current code looks like this.</p>
  
  <pre class="lang-dart prettyprint-override"><code>Future&lt;bool&gt; getNameDate(BuildContext context)
    async
    {
      return showDialog&lt;bool&gt;(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("Save Event"),
            content: new Column(
              children: &lt;Widget&gt;[
                new Expanded(
                  child: new TextField(
                    autofocus: true,
                    decoration: new InputDecoration(
                        labelText: "Event Name"
                    ),
                    onChanged: (value) {
                      name = value;
                    },
                    onSubmitted: (value) {
                    },
                  ),
                ),
                new Expanded(
                    child: new Row(
                      children: &lt;Widget&gt;[
                        new Text("Date of Event "),
                        new RaisedButton(
                            child: Text(DateFormat("dd/MM/yyyy").format(when)),
                            onPressed: () async {
                              DateTime picked = await showDatePicker(
                                context: context,
                                initialDate: when,
                                firstDate: DateTime(2015, 8),
                                lastDate: DateTime(2101),
                              );
                              setState(() {
                                when = picked ;
                              });
                            }),
                      ],
                    )
                )
              ],
            ),
            actions: &lt;Widget&gt;[
              new FlatButton(
                  child: const Text('OK'),
                  onPressed: () {
                    Navigator.of(context).pop(true);
                  }),
              new FlatButton(
                  child: const Text("CANCEL"),
                  onPressed: () {
                    Navigator.of(context).pop(false);
                  }),
            ],
          );
        },
      );
    }
  </code></pre>
  
  <p>Sorry about the comment. It would be nice if it were possible to reply to answers in a better fashion. Anyway, I had hoped I could create a more generic "Stateful dialog" So I created something like this..</p>
  
  <pre class="lang-dart prettyprint-override"><code>class StateDialog extends StatefulWidget
  {
    final AlertDialog dialog;
    StateDialog({Key key, @required this.dialog}) : super (key: key);
  
    @override
    StateDialogState createState() =&gt; StateDialogState(dialog: dialog);
  
  }
  
  class StateDialogState extends State&lt;StateDialog&gt;
  {
    final AlertDialog dialog;
    StateDialogState({@required this.dialog});
    @override
    Widget build(_) {
      return dialog;
    }
  }
  
  </code></pre>
  
  <p>Then in my existing function changed it to..</p>
  
  <pre class="lang-dart prettyprint-override"><code>    return showDialog&lt;bool&gt;(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context)
        {
          return StateDialog(dialog: AlertDialog(
            title: Text("Save Event"),
            content: new Column(
              children: &lt;Widget&gt;[
  etc...
  </code></pre>
  
  <p>But this still doesn't update the text in the date button. I would be nice to understand why.</p>