title: Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe. how to solve this?
body: <p>I am trying to integrate stripe payment in flutter mobile app. After finishing the payment, I want the app to execute <code>Navigator.pop(context)</code>. However, I get error message that says</p>
  <blockquote>
  <p>Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
  E/flutter ( 2773): At this point the state of the widget's element tree is no longer stable.</p>
  </blockquote>
  <p>This is my code for stripe payment</p>
  <pre><code>class ExistingCardsPage extends StatefulWidget {
   static const String id = 'exsiting-card';
   ExistingCardsPage({Key key}) : super(key: key);
  
   @override
   ExistingCardsPageState createState() =&gt; ExistingCardsPageState();
  }
  
  class ExistingCardsPageState extends State&lt;ExistingCardsPage&gt; {
   List cards = [];
   StripeService _service = StripeService();
  
   Future&lt;StripeTransactionResponse&gt; payViaExistingCard(
       BuildContext context, card, amount) async {
      await EasyLoading.show(status: &quot;Please wait....&quot;);
      var expiryArr = card['expiryDate'].split('/');
      CreditCard stripeCard = CreditCard(
       number: card['cardNumber'],
       expMonth: int.parse(expiryArr[0]),
       expYear: int.parse(expiryArr[1]),
     );
     var response = await StripeService.payViaExistingCard(
        amount: '${amount}00', currency: 'USD', card: stripeCard);
      await EasyLoading.dismiss();
      ScaffoldMessenger.of(context).showSnackBar(
         SnackBar(
           content: Text(response.message),
           duration: new Duration(milliseconds: response.success == true ? 1200 : 3000),
         )
     ).closed.then((_) {
       Navigator.pop(context); /////THIS IS THE ERROR/////
  
     });
  
     return response;
  }
  
   @override
   Widget build(BuildContext context) {
     final orderProvider = Provider.of&lt;OrderProvider&gt;(context);
      return Scaffold(
       appBar: AppBar(
      iconTheme: IconThemeData(color: Colors.white),
      title: Text('Choose existing card', style: TextStyle(color: Colors.white),),
    ),
    body: FutureBuilder&lt;QuerySnapshot&gt;(
      future: _service.cards.get(),
      builder: (BuildContext context, AsyncSnapshot&lt;QuerySnapshot&gt; snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }
  
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Center(child: CircularProgressIndicator());
        }
  
        if(snapshot.data.size==0){
          return Center(
            child: Text('No Credit Card in your account'));
        }
  
        return Container(
          padding: EdgeInsets.only(left: 8, top: 10, right: 8, bottom: 10),
          child: ListView.builder(
            itemCount: snapshot.data.docs.length,
            itemBuilder: (BuildContext context, int index) {
              var card = snapshot.data.docs[index];
              return InkWell(
                onTap: () {
                  payViaExistingCard(context, card, orderProvider.amount).then((response) {
                    if(response.success==true){
                      orderProvider.paymentStatus(response.success);
                    }
                  });
                },
                child: CreditCardWidget(
                  cardNumber: card['cardNumber'],
                  expiryDate: card['expiryDate'],
                  cardHolderName: card['cardHolderName'],
                  cvvCode: card['cvvCode'],
                  showBackView: false,
                  onCreditCardWidgetChange: (brand) {
                    print(brand);
                  },
                ),
              );
            },
          ),
        );
      },
    )
  );
  }
  }
  </code></pre>
  <p>Does anyone know what is wrong with the code?</p>