title: Flutter initial route using provider value
body: <p>I just started using provider as a state management for flutter. I have a value in a provider to be used for the initial login. <strong>isLogin</strong> will return true or false and depending on that it will redirect the user to home or login page. I'm getting the error below:</p>
  <p><em>Could not find the correct Provider above this MyApp Widget</em></p>
  <p>Plus, is this a good way of doing authentication or is there a better way. I'm using laravel API for authentication.</p>
  <p><strong>Main.dart</strong></p>
  <pre><code>void main() {
    runApp(MyApp());
  }
  
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider&lt;UserProvider&gt;(
        create: (context) =&gt; UserProvider(),
        child: MaterialApp(
        initialRoute:Provider.of&lt;UserProvider&gt;(context,listen:false).isLogin?'/':'/login',
        routes: {
          '/':(_)=&gt;HomePage(),
          '/donation-history':(_)=&gt;DonationHistoryPage(),
          '/login':(_)=&gt;LoginPage(),
          '/new-donation':(_)=&gt;NewDonation()
        },
        debugShowCheckedModeBanner:false,
        title: 'RedHero',
        theme: ThemeData(
          primaryColor: kPrimaryColor,
          accentColor: Colors.white,
          scaffoldBackgroundColor: kBackgroundColor,
          fontFamily: &quot;Poppins&quot;,
          textTheme: TextTheme(
            bodyText1: TextStyle(color: kBodyTextColor)
          )
        ),
      ),
    );
  }
  </code></pre>