title: Flutter: local notification plugin, navigate to specific screen when the user tap the notification
body: <p>I`m using local notification plugin and everything works fine except that when i tap on the notification.i want to navigate to specific screen when the user tap the notification</p>
  
  <pre><code>Future onSelectNotification(String payload) async {
      //convert payload json to notification model object
      try{
      Map notificationModelMap = jsonDecode(payload);
      NotificationModel model = NotificationModel.fromJson(notificationModelMap);
  
      await Navigator.push(
          context,// it`s null!
          new MaterialPageRoute(
              builder: (context) =&gt; CommitmentPage(model)));}
              catch(e){print(e.toString());}
    }
  </code></pre>
  
  <p>but the context always null and gives me an exception
  <code>NoSuchMethodError: The method 'ancestorStateOfType' was called on null</code>.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>i tried to use navigatorKey and pass it to material app as suggested by @Günter Zöchbauer but it gives me another exception</p>
  
  <pre><code>Navigator operation requested with a context that does not include a Navigator.
  The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget
  </code></pre>
  
  <p><strong>main.dart</strong></p>
  
  <pre><code>void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
  
  static final navigatorKey = new GlobalKey&lt;NavigatorState&gt;();
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        navigatorKey:navigatorKey ,
        title: 'notification',
        theme: ThemeData(
          primarySwatch: Colors.purple,
        ),
        home: new RootPage(auth: new Auth(),),
      );
    }
  
  }
  </code></pre>
  
  <p><strong>ReminderPage</strong> </p>
  
  <pre><code>   class ReminderPage extends StatefulWidget {
  
      @override
        _ReminderPageState createState() =&gt; _ReminderPageState();
  
      }
  
  class _ReminderPageState extends State&lt;ReminderPage&gt; {
    final flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
  ....
  
   @override
    void initState() {
      super.initState();
  
      _initLocalNotification();
  ....
  
    }
  
  
  // this method is called when u tap on the notification
   Future onSelectNotification(String payload) async {
  
      //convert payload json to notification model object
      Map notificationModelMap = jsonDecode(payload);
      NotificationModel model = NotificationModel.fromJson(notificationModelMap);
  
      try{
     await Navigator.push(
          MyApp.navigatorKey.currentState.context,
          new MaterialPageRoute(
              builder: (context) =&gt; CommitmentPage(model)));}
              catch(e){print(e.toString());}
  
  
    }
  
  }
  </code></pre>
  
  <p><strong>Edit 2</strong>
  instead of using </p>
  
  <pre><code> await Navigator.push(
              MyApp.navigatorKey.currentState.context,
              new MaterialPageRoute(
                  builder: (context) =&gt; CommitmentPage(model)));}
                  catch(e){print(e.toString());}
  </code></pre>
  
  <p>i used </p>
  
  <pre><code>await  MyApp.navigatorKey.currentState.push(MaterialPageRoute(builder: (context) =&gt; CommitmentPage(model)));
  </code></pre>
  
  <p>and it worked fine, but when i tap on the notification after killing the app, it takes me to the home page not to the desired one! 
  i think navigatorKey has not been initialized yet!</p>