title: Flutter context problem with onGenerateRoute and builder in MaterialApp
body: <p>StackOverflow community!</p>
  
  <p>What I'm trying to build is a mobile/web application in Flutter with a static "always open" drawer on the web.</p>
  
  <p>So what I did is I've created and router (with Fluro) and use it in the onGenerateRoute function of my MaterialApp. The child will be created from the router and I'll pass it to the "MainLayout".</p>
  
  <pre><code>  @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'MyApp',
        theme: appTheme,
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          FlutterI18nDelegate(
            translationLoader: FileTranslationLoader(
                basePath: 'assets/i18n',
                fallbackFile: 'de_DE',
                useCountryCode: true),
          ),
        ],
        supportedLocales: [
          const Locale('en', 'US'), // English
          const Locale('de', 'DE'), // German
        ],
        initialRoute: NavUtils.initialUrl,
        onGenerateRoute: router.generator,
        navigatorKey: _navigatorKey,
        builder: (context, child) {
          return MultiBlocProvider(
            providers: [
              BlocProvider.value(
                value: _authenticationBloc,
              ),
              BlocProvider.value(
                value: _userSettingsBloc,
              ),
              BlocProvider.value(
                value: _organizationBloc,
              ),
              BlocProvider.value(
                value: _reportsBloc,
              ),
            ],
            child: BlocBuilder&lt;AuthenticationBloc, AuthenticationState&gt;(
              builder: (context, state) {
                if (state is AuthenticationAuthenticated) {
                  return MainLayout(
                    child: child,
                    drawerKey: _drawerKey,
                    navigatorKey: _navigatorKey,
                  );
                } else {
                  return Scaffold(
                    backgroundColor: mainBackground,
                    drawer: DrawerMenu(
                      navigatorKey: _navigatorKey,
                      drawerKey: _drawerKey,
                    ),
                    body: SafeArea(
                      child: child,
                    ),
                  );
                }
              },
            ),
          );
        },
      );
    }
  </code></pre>
  
  <p>and the content of my MainLayout()</p>
  
  <pre><code>class MainLayout extends StatelessWidget {
    final Widget child;
    final GlobalKey&lt;ScaffoldState&gt; drawerKey;
    final GlobalKey&lt;NavigatorState&gt; navigatorKey;
    MainLayout(
        {Key key,
        @required this.child,
        @required this.drawerKey,
        @required this.navigatorKey})
        : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        key: drawerKey,
        backgroundColor: mainBackground,
        drawer: MediaQuery.of(context).size.width &gt;= 769
            ? null
            : DrawerMenu(
                navigatorKey: navigatorKey,
                drawerKey: drawerKey,
              ),
        body: SafeArea(
          child: Container(
            child: Row(
              children: &lt;Widget&gt;[
                MediaQuery.of(context).size.width &gt;= 769
                    ? DrawerMenu(
                        navigatorKey: navigatorKey,
                        drawerKey: drawerKey,
                      )
                    : Container(),
                Expanded(
                  child: child,
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>The problem I have is, that ie. my DrawerMenu() can't find the navigator in the context. Leading me to problems like I can't use any tooltip widget because it's not finding the overlay.</p>
  
  <pre><code>════════ Exception caught by widgets library ═══════════════════════════════════
  No Overlay widget found.
  The relevant error-causing widget was
      Tooltip 
  </code></pre>
  
  <p>As soon as I'll wrap my whole MaterialApp in another MaterialApp it's working fine, but I destroy my routing.</p>
  
  <p>Can anybody help me with this?
  Is this enough information to even provide any help?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>With your question and your answer here on <a href="https://stackoverflow.com/questions/44004451/navigator-operation-requested-with-a-context-that-does-not-include-a-navigator">StackOverflow</a> I figured out, that I have to use this different. What I did is to "extract" the whole stuff and make created a Navigator in the Scaffold, like this:</p>
  
  <pre><code>  @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'MyApp',
        theme: appTheme,
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          FlutterI18nDelegate(
            translationLoader: FileTranslationLoader(
                basePath: 'assets/i18n',
                fallbackFile: 'de_DE',
                useCountryCode: true),
          ),
        ],
        supportedLocales: [
          const Locale('en', 'US'), // English
          const Locale('de', 'DE'), // German
        ],
        initialRoute: NavUtils.initialUrl,
        onGenerateRoute: (RouteSettings settings) {
          _navigatorKey.currentState.popAndPushNamed(settings.name);
        },
        home: Builder(
          builder: (context) =&gt; MultiBlocProvider(
            providers: [
              BlocProvider.value(
                value: _authenticationBloc,
              ),
              BlocProvider.value(
                value: _userSettingsBloc,
              ),
              BlocProvider.value(
                value: _organizationBloc,
              ),
              BlocProvider.value(
                value: _reportsBloc,
              ),
            ],
            child: Scaffold(
              key: _drawerKey,
              backgroundColor: mainBackground,
              drawer: MediaQuery.of(context).size.width &gt;= 769
                  ? null
                  : DrawerMenu(
                      navigatorKey: _navigatorKey,
                      drawerKey: _drawerKey,
                    ),
              body: SafeArea(
                child: Container(
                  child: Row(
                    children: &lt;Widget&gt;[
                      MediaQuery.of(context).size.width &gt;= 769
                          ? DrawerMenu(
                              navigatorKey: _navigatorKey,
                              drawerKey: _drawerKey,
                            )
                          : Container(),
                      Expanded(
                        child: Navigator(
                          key: _navigatorKey,
                          initialRoute: NavUtils.initialUrl,
                          onGenerateRoute: router.generator,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    }
  </code></pre>
  
  <p>The only problem now is, how do I get the URL, a user enters in the browser address bar, to my navigator. </p>
  
  <p>For now I'm using <code>_navigatorKey.currentState.popAndPushNamed(settings.name);</code> in my MaterialApp but this removes the URL in the address bar after hitting enter. (But it actually navigates to the correct page)</p>
  
  <p>Is there a way to keep this consistent?</p>