How to navigate without context in flutter app?

后端 未结 2 2020
一生所求
一生所求 2020-12-06 04:56

I have an app that recieves push notification using OneSignal. I have made a notification opened handler that should open specific screen on click of the notification. How c

相关标签:
2条回答
  • 2020-12-06 05:12

    You can use this wonderful plugin: https://pub.dev/packages/get

    Description from the package: A consistent navigation library that lets you navigate between screens, open dialogs, and display snackbars from anywhere in your code without context.

    Get.to(NextScreen()); // look at this simplicity :)
    Get.back(); //  pop()
    Get.off(NextScreen()); // clears the previous routes and opens a new screen.
    
    0 讨论(0)
  • 2020-12-06 05:20

    Look at this here: https://github.com/brianegan/flutter_redux/issues/5#issuecomment-361215074

    You can set a global key for your navigation:

    final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
    

    Pass it to MaterialApp:

    new MaterialApp(
          title: 'MyApp',
          onGenerateRoute: generateRoute,
          navigatorKey: navigatorKey,
        );
    

    Push routes:

    navigatorKey.currentState.pushNamed('/someRoute');
    
    0 讨论(0)
提交回复
热议问题