title: Can you have different conditional MaterialApp s returned?
body: <p>Basically, I want to return an OTP (One Time Pin) input screen if the app opens and there isn't a valid user file, otherwise the app should open with a menu (Using <code>Provider</code>).</p>
  <p>What I tried was:</p>
  <ol>
  <li><code>Main</code> calls <code>runApp(const MyApp());</code> which is stateless.</li>
  <li>MyApp's build returns <code>MultiProvider</code> with its child <code>const AuthenticatedMaterialApp(),</code> which is a stateful widget.</li>
  <li>Here I tried various things , including setting different routes based on the provided values, but keep getting unexpected (for me) results; e.g. in _AuthenticatedMaterialAppState:</li>
  </ol>
  <pre><code>class _AuthenticatedMaterialAppState extends State&lt;AuthenticatedMaterialApp&gt; {
    late ConnectionNotifier connectionNotifier;
    late Authenticate auth;
    late bool isUserOkay;
  
    @override
    void didChangeDependencies() {
      super.didChangeDependencies();
    }
  
    @override
    Widget build(BuildContext context) {
      connectionNotifier = context.read&lt;ConnectionNotifier&gt;();
      auth = context.watch&lt;Authenticate&gt;();
      isUserOkay = (auth.isActive &amp;&amp; auth.isKnown);
      developer.log('build isUserOkay:$isUserOkay isKnown: ${auth.isKnown}',
          name: 'AuthenticatedMaterialApp');
  
      String initRoute = (!isUserOkay) ? '/otp' : '/menu';
      developer.log('initRoute $initRoute', name: 'AuthenticatedMaterialApp');
     
      if (!isUserOkay) {
        developer.log('isUserOkay: $isUserOkay return OTP app ', name: 'AuthenticatedMaterialApp');
        return MaterialApp(
          navigatorObservers: [routeObserver],
          title: 'Named Routes',
          theme: ThemeData(scaffoldBackgroundColor: Colors.white),
          initialRoute: '/otp',
          routes: {
            '/otp': (context) =&gt; const OTPScreen(),
          },
        );
      } else {
        developer.log('isUserOkay: $isUserOkay return menu app ', name: 'AuthenticatedMaterialApp');
        return MaterialApp(
          navigatorObservers: [routeObserver],
          title: 'Named Routes',
          theme: ThemeData(scaffoldBackgroundColor: Colors.white),
          initialRoute: '/menu',
          routes: {
            '/menu': (context) =&gt; const MenuScreen(),
            '/stocks': (context) =&gt; const StocksRoute(),
            '/stocks/stock': (context) =&gt; const StockPage(),
            '/clients': (context) =&gt; const ClientsRoute(),
            '/clients/client': (context) =&gt; const ClientPage(),
            '/viewings': (context) =&gt; const ViewingsRoute(),
            '/viewings/viewing': (context) =&gt; const ViewingPage(),
            '/offers': (context) =&gt; const OffersRoute(),
            '/offers/offer': (context) =&gt; const OfferPage(),
            '/checkin': (context) =&gt; const CheckinScreen(),
            '/calendar': (context) =&gt; const CalendarScreen(),
            '/reports': (context) =&gt; const ReportsScreen(),
            '/calculators': (context) =&gt; const CalculatorsScreen(),
            '/test': (context) =&gt; const TestRoute(),
          },
        );
      }
    }
  }
  </code></pre>
  <p>... eventually generates output that reads <code>[AuthenticatedMaterialApp] isUserOkay: true return menu app </code>, but what is shown on the screen is the OTP screen.
  Why? - has it something to do with AuthenticatedMaterialApp being a <code>const</code>, or?</p>
  <p>I also tried registering all the routes but having <code> initialRoute:</code> be a variable string but get basically the same result.</p>
  <p>I can get it working by creating a separate 'home` route, and checking the user there and ~redirecting like:</p>
  <pre><code>class _HomeState extends State&lt;Home&gt; {
    late Authenticate auth;
  
    @override
    Widget build(BuildContext context) {
      auth = context.watch&lt;Authenticate&gt;();
      developer.log('build', name: '_HomeScreenState');
      if (auth.isKnown) {
        if (auth.isActive == true) {
          return const MenuScreen();
        } else if (auth.isActive == false) {
          return const OTPScreen();
        }
      }
      return Container();
    }
  }
  </code></pre>
  <p>while I have all the routes including OTP, menu etc all registered in the AuthenticatedMaterialApp, which I suppose is fine, but I would like to understand why my initial approach doesn't/can't work?</p>