title: flutter navigator pop dialog - error - Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null
body: <p>I have got this piece of pop up Dialog() code in flutter 
  <a href="https://gist.github.com/axilaris/2b186c7a4073671128e8cacc09dfc384" rel="noreferrer">https://gist.github.com/axilaris/2b186c7a4073671128e8cacc09dfc384</a>, if you check out the code somewhere right at the bottom</p>
  
  <pre><code>class PurchaseDialog extends StatefulWidget with NavigationStates {
  ...
  class _PurchaseDialogState extends State&lt;PurchaseDialog&gt; {
  ...
    @override
    Widget build(BuildContext context) {
      return Dialog(
  ...
   showSecondaryButton(BuildContext context) {
  ...
  Navigator.of(context).pop(); &lt;--- here is the problem
  </code></pre>
  
  <p>whenever it calls </p>
  
  <pre><code>Navigator.of(context).pop();
  </code></pre>
  
  <p>it will cause the following error</p>
  
  <pre><code>[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null.
  </code></pre>
  
  <p>this looks like a duplicate of this <a href="https://stackoverflow.com/questions/56362432/nosuchmethoderror-the-method-ancestorstateoftype-was-called-on-null-with-awai">NoSuchMethodError: The method &#39;ancestorStateOfType&#39; was called on null with await and async method</a>, but i'ved tried the solutions it does not work. (context can only set once, and checking mounted variable have no effect).</p>
  
  <p>How to resolve this ? So far it dismiss the dialog (with pop() so its correct behaviour), but I dont want this error coming out. </p>
  
  <p>UPDATE info:
  The PurchaseDialog() above is called in this way:</p>
  
  <pre><code>    showDialog(
        context: context,
        builder: (BuildContext context) =&gt; PurchaseDialog(),
      ).then((value) {
        setState(() {
        });
      });
  </code></pre>
  
  <p>here are trace prints: <a href="https://gist.github.com/axilaris/6d8db8824b0b89e33fee7ddfdd238e34" rel="noreferrer">https://gist.github.com/axilaris/6d8db8824b0b89e33fee7ddfdd238e34</a></p>