title: Flutter navigatorkey + GlobalKey: "method 'pushedName' was called on null"
body: <p>I've found the <a href="https://github.com/brianegan/flutter_redux/issues/5" rel="noreferrer">"GlobalKey NavigatorState" solution for middleware here</a> but was unable to overcome the error "The method 'pushedNamed' was called on null".  I then found this <a href="https://stackoverflow.com/questions/50303441/flutter-redux-navigator-globalkey-currentstate-returns-null%20%22%22">alternative solution to fix the issue</a> using a separate class and static variable, but it yielded the same error.  <strong>All I really need is a very basic example</strong> of the setup and how to call the "pushedNamed" function somewhere else.</p>
  
  <p><strong>Current code</strong></p>
  
  <p>initialize GlobalKey in separate folder:</p>
  
  <pre><code>class NavKey{
    static final navKey = new GlobalKey&lt;NavigatorState&gt;();
  }
  </code></pre>
  
  <p>main.dart:</p>
  
  <pre><code>import 'package:eumag/assets/tools/route_navigation_constants.dart';
  
      ...
  
    @override
    Widget build(BuildContext context) {
      return StoreProvider&lt;AppState&gt;(
        store: store,
        child: MaterialApp(
          theme: ThemeData.dark(),
          navigatorKey: NavKey.navKey,
          routes: &lt;String, WidgetBuilder&gt;{
            ROUTE_LOGIN_PAGE: (BuildContext context) =&gt; LoginPage(store),
            ROUTE_MAIN_PAGE: (BuildContext context) =&gt; MainPage(store),
          },
          home: StoreBuilder&lt;AppState&gt;(
            builder: (BuildContext context, Store&lt;AppState&gt; store) =&gt;
                LoginPage(store),
          ),
        ),
      );
    }
  </code></pre>
  
  <p>middleware.dart:</p>
  
  <pre><code>import 'package:eumag/assets/tools/route_navigation_constants.dart';
  
  void appStateMiddleware (Store&lt;AppState&gt; store, action, NextDispatcher next) async{
  
    final navigatorKey = NavKey.navKey;
  
    if (action is UpdateRoomStatus){
      navigatorKey.currentState.pushNamed(ROUTE_MAIN_PAGE);
      store.dispatch(createSocketConnection);
    }
    next(action);
  }
  </code></pre>