title: Flutter Closing Dialog isn't working - error _debugLocked'
body: <p>I have a button when pressed it opens a dialog like this:</p>
  <pre><code>TextButton(
         onPressed: () {
           showDialog(
               context: context, builder: (_) =&gt; ReviewDialog(context));
         },
      )
  </code></pre>
  <p>and the Review Dialog code is the below, inside it there is a button when pressed it calls a future function to add some data to firestore.</p>
  <pre><code>Widget ReviewDialog(dialogcontext) {
  return Dialog(
    child: ElevatedButton(
           onPressed: () {SendReview(dialogcontext);}
    );
  }
  </code></pre>
  <p>now the objective is from this future function, after adding the data to database, I would like to close the dialog. the code is:</p>
  <pre><code>   Future SendReview(dialogcontext) async {
  CollectionReference reviewscollectionref =
      FirebaseFirestore.instance.collection('ReviewsCollection');
  QuerySnapshot firstquerySnapshot = await reviewscollectionref
      .where('Review_globalid', isEqualTo: globaluserid)
      .where('Review_bpid', isEqualTo: selectedbusinessprofileid)
      .get();
       
        reviewscollectionref.add({
      'Review_globalid': globaluserid,
      'Review_globalname': globalusername,
      'Review_date': DateTime.now(),
      'Review_bpid': selectedbusinessprofileid,
      'Review_description': reviewcontroller.text,
      'Review_status': &quot;Active&quot;,
    });
  
       Flushbar(
      title: &quot;Success&quot;,
      message: &quot;Review is added successfully&quot;,
      duration: Duration(seconds: 3),
    )..show(context);  ///here I am showing the flushbar in the original page.
  
    Navigator.of(dialogcontext, rootNavigator: true).pop(); // here I would like to close the dialog.
  }
  </code></pre>
  <p>the problem is, the code like this is giving the error: !_debugLocked'</p>
  <p>I did some search and understood that this is because it is Future function, I tried the below solutions but didn't solve the issue:</p>
  <pre><code>Future.delayed(Duration.zero, () {
  Navigator. ...
  });
  </code></pre>
  <p>in this solution, no error but dialog doesn't close.</p>
  <pre><code>SchedulerBinding.instance.addPostFrameCallback((_) {
  Navigator. ...
   });
  </code></pre>
  <p>and this one is generating error: Route Lifecycle.pop.index)': is not true</p>