title: Tried to listen to a value exposed with provider, from outside of the widget tree
body: <p>So, I have a project in flutter and I'm trying to build a list of Cards where the contents depends on my OrderModel class and I'm trying to use Provider to achieve this, but I get this error:</p>
  
  <p>════════ Exception caught by scheduler library ══════════════════════════</p>
  
  <p>Tried to listen to a value exposed with provider, from outside of the widget tree.</p>
  
  <p>This is likely caused by an event handler (like a button's onPressed) that called
  Provider.of without passing <code>listen: false</code>.</p>
  
  <p>To fix, write:
  Provider.of(context, listen: false);</p>
  
  <p>It is unsupported because may pointlessly rebuild the widget associated to the
  event handler, when the widget tree doesn't care about the value.
  'package:provider/src/provider.dart':
  Failed assertion: line 193 pos 7: 'context.owner.debugBuilding || listen == false || _debugIsInInheritedProviderUpdate'</p>
  
  <p>When the exception was thrown, this was the stack</p>
  
  <p>#2      Provider.of 
  package:provider/src/provider.dart:193</p>
  
  <p>#3      _OrderHistoryState._onAfterBuild 
  package:shinier_store/screens/order_history.dart:60</p>
  
  <p>#4      _OrderHistoryState.build. 
  package:shinier_store/screens/order_history.dart:67</p>
  
  <p>#5      SchedulerBinding._invokeFrameCallback 
  package:flutter/…/scheduler/binding.dart:1102</p>
  
  <p>#6      SchedulerBinding.handleDrawFrame 
  package:flutter/…/scheduler/binding.dart:1049
  ...</p>
  
  <p>═════════════════════════════════════════════════════════
  Stacktrace for the Provider call at _onAfterBuild()</p>
  
  <pre><code>I/flutter ( 3092): #0      _AssertionError._doThrowNew  (dart:core-patch/errors_patch.dart:42:39)
  I/flutter ( 3092): #1      _AssertionError._throwNew  (dart:core-patch/errors_patch.dart:38:5)
  I/flutter ( 3092): #2      Provider.of package:provider/src/provider.dart:193
  I/flutter ( 3092): #3      _OrderHistoryState._onAfterBuild package:shinier_store/screens/order_history.dart:61
  I/flutter ( 3092): #4      _OrderHistoryState.build.&lt;anonymous closure&gt; 
  package:shinier_store/screens/order_history.dart:71
  I/flutter ( 3092): #5      SchedulerBinding._invokeFrameCallback 
  package:flutter/…/scheduler/binding.dart:1102
  I/flutter ( 3092): #6      SchedulerBinding.handleDrawFrame 
  package:flutter/…/scheduler/binding.dart:1049
  I/flutter ( 3092): #7      SchedulerBinding._handleDrawFrame 
  package:flutter/…/scheduler/binding.dart:957
  I/flutter ( 3092): #8      _rootRun  (dart:async/zone.dart:1126:13)
  I/flutter ( 3092): #9      _CustomZone.run  (dart:async/zone.dart:1023:19)
  I/flutter ( 3092): #10     _CustomZone.runGuarded  (dart:async/zone.dart:925:7)
  I/flutter ( 3092): #11     _invoke  (dart:ui/hooks.dart:259:10)
  I/flutter ( 3092): #12     _drawFrame  (dart:ui/hooks.dart:217:3)
  </code></pre>
  
  <p>I don't know how can I possibly solve it since I added the listen:false to my Provider call. I tried using WidgetBinding, cause I thought the Provider call should be made after build is done but that didn't seem to solve the problem.</p>
  
  <p>Here are the codes:</p>
  
  <p>OrderModel class</p>
  
  <pre class="lang-dart prettyprint-override"><code>class OrderModel extends ChangeNotifier {
    List&lt;Order&gt; myOrders;
    bool isLoading = true;
    String errMsg;
    int page = 1;
    bool endPage = false;
  
    void getMyOrder({UserModel userModel}) async {
      try {
        isLoading = true;
        notifyListeners();
        myOrders = await WooCommerce().getMyOrders(userModel: userModel, page: 1);
        page = 1;
        errMsg = null;
        isLoading = false;
        endPage = false;
        notifyListeners();
      } catch (err) {
        errMsg =
            "There is an issue with the app during request the data, please contact admin for fixing the issues " +
                err.toString();
        isLoading = false;
        notifyListeners();
      }
    }
  
    void loadMore({UserModel userModel}) async {
      try {
        isLoading = true;
        page = page + 1;
        notifyListeners();
        var orders =
            await WooCommerce().getMyOrders(userModel: userModel, page: page);
        myOrders = [...myOrders, ...orders];
        if (orders.length == 0) endPage = true;
        errMsg = null;
        isLoading = false;
        notifyListeners();
      } catch (err) {
        errMsg =
            "There is an issue with the app during request the data, please contact admin for fixing the issues " +
                err.toString();
        isLoading = false;
        notifyListeners();
      }
    }
  }
  </code></pre>
  
  <p>order_history.dart - state class</p>
  
  <pre class="lang-dart prettyprint-override"><code>class _OrderHistoryState extends State&lt;OrderHistory&gt; {
    void _onAfterBuild(BuildContext context){
       Provider.of&lt;OrderModel&gt;(context, listen: false)
          .getMyOrder(userModel: Provider.of&lt;UserModel&gt;(context));
    }
  
    @override
    Widget build(BuildContext context) {
      var formatter = DateFormat('dd-MM-yyyy');
      var model = Provider.of&lt;OrderModel&gt;(context);
      WidgetsBinding.instance.addPostFrameCallback((_) =&gt; _onAfterBuild(context));
  
      return Scaffold(
        appBar: AppBar(
            title: Text(
              'Order History',
              style: TextStyle(fontWeight: FontWeight.bold),
            ),
            elevation: 0.0),
        body: model.myOrders == null ? Center() :
        Padding(
          padding: const EdgeInsets.all(10.0),
          child: ListView.separated(
            separatorBuilder: (_, __) =&gt; SizedBox(height: 10.0),
            itemCount: model.myOrders.length,
            itemBuilder: (context, index) {
              String stat = model.myOrders[index].status;
              return Card(
                color: _buildColor(stat),
                elevation: 3.5,
                ...
    }
  }
  </code></pre>
  
  <p>main.dart - build method</p>
  
  <pre class="lang-dart prettyprint-override"><code>  @override
    Widget build(BuildContext context) {
      return MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (_) =&gt; UserModel()),
          ChangeNotifierProvider(create: (_) =&gt; CartModel()),
          ChangeNotifierProvider(create: (_) =&gt; SearchModel()),
          ChangeNotifierProvider(create: (_) =&gt; OrderModel()),
        ],
        child: MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primaryColor: Colors.white,
            backgroundColor: Colors.white,
            canvasColor: Colors.white,
          ),
          home: MainTabs(),
          debugShowCheckedModeBanner: false,
          localizationsDelegates: [
            i18n,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          supportedLocales: i18n.supportedLocales,
        ),
      );
    }
  </code></pre>