title: Dismissing AlertDialog in Flutter
body: <p>I have simple Flutter app with list of items that are loaded from Firebase database (Cloud Firestore).</p>
  
  <p><a href="https://i.stack.imgur.com/vNTQw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vNTQw.png" alt="enter image description here"></a></p>
  
  <p>As you can see - there is button for adding items and each item can be deleted or edited. When I press edit button for selected item, AlertDialog with TextField appears, in this TextField user can see current item name and edit it.  <strong>I have problems only with dismissing dialog after editing.</strong></p>
  
  <pre><code>   new IconButton(
        icon: new Icon(Icons.edit, color: Colors.white),
        onPressed: (){ showItemUpdateDialog(context, document); }
     )
     .......
  
  
  void showItemUpdateDialog(BuildContext context, DocumentSnapshot item) {
  
    String itemName = "";
    var textContoller = new TextEditingController();
    textContoller.text = item['name'];
  
    var dialog = new AlertDialog(
      title: new Text("item name"),
      content: new TextField(
        controller: textContoller,
        onChanged: (value) {newName = value;},
      ),
      actions: &lt;Widget&gt;[
        new FlatButton(
          child: Text("cancel"),
          onPressed: (){
            Navigator.pop(context);
          },
        ),
        new FlatButton(
            child: Text("Update"),
            onPressed: () { 
              updateItemOnServer(item, newName); 
              Navigator.pop(context); 
            }
        )
      ],
    );
  
    showDialog(context: context, child: dialog);
  }
  </code></pre>
  
  <p>Value is updating correctly but AlertDialog is not dismissed. Error code is below. I think that it is due to that is was called by item that was modified and updated from server.</p>
  
  <blockquote>
    <p>flutter: The following assertion was thrown while handling a gesture:
    flutter: Looking up a deactivated widget's ancestor is unsafe.
    flutter: At this point the state of the widget's element tree is no
    longer stable. To safely refer to a flutter: widget's ancestor in its
    dispose() method, save a reference to the ancestor by calling flutter:
    inheritFromWidgetOfExactType() in the widget's didChangeDependencies()
    method.</p>
  </blockquote>