title: How to set dynamic initialRoute based on sharedPrefs value in flutter?
body: <p>Currently, I am working around routes and i wanted to set initialRoute in my app based on sharedPreferences value.</p>
  
  <p>I am using Statedulwidget for my MaterialAppWidget and using setState() method once the data from sharedPrefs is fetched. But, every time i am getting the same screen.</p>
  
  <pre><code>class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() =&gt; _MyAppState();
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
    int initScreen = 0;
  
    initPrefs() async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      initScreen = prefs.getInt("initScreen");
  
      print("initScreen ${initScreen}");
      setState(() {});
    }
  
    @override
    void initState() {
      super.initState();
  
      initPrefs();
    }
  
    @override
    Widget build(BuildContext context) {
      print("initScreen2 ${initScreen}");
      return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'Flutter Authentication',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          initialRoute: initScreen == 0 || initScreen == null
              ? MediatorPage.routeName
              : PopUntilPage.routeName,
          routes: {
            CloudGroupCreate.routeName: (context) =&gt; CloudGroupCreate(),
            CloudDashboard.routeName: (context) =&gt; CloudDashboard(),
            PopUntilPage.routeName: (context) =&gt; PopUntilPage(),
            ProviderWithFutureBuilderApp.routeName: (context) =&gt;
                ProviderWithFutureBuilderApp(),
            MediatorPage.routeName: (context) =&gt; MediatorPage(),
          },
          );
    }
  }
  </code></pre>
  
  <p>I do not want to use direct widget using home property app. I just want to navigate through only and only using named routes.</p>
  
  <p>Can anyone suggest how to do it properly ? </p>
  
  <p>Thanks.</p>