简体   繁体   English

Firebase 推送通知路由 flutter

[英]Firebase push notification routing flutter

I have the push notifications set up using firebase_messaging on my app.我在我的应用程序上使用 firebase_messaging 设置了推送通知。 When the app is opened from a terminated state via a push notification, I navigate to a specific route (ProductPage) and upon pressing the back button, I get a black screen as there are no routes on the navigation stack当通过推送通知从已终止的 state 打开应用程序时,我导航到特定路线 (ProductPage) 并在按下后退按钮时出现黑屏,因为导航堆栈上没有路线

When I press the back button from the app bar or trigger the hardware back button on an Android device, how can I make the app navigate to the initial route instead of seeing a black screen?当我按下应用栏的后退按钮或触发 Android 设备上的硬件后退按钮时,如何让应用导航到初始路径而不是看到黑屏?

I tried utilizing the onWillPop callback of the WillPopScope widget, but the callback exits the app entirely instead of navigating to the new route.我尝试使用WillPopScope小部件的onWillPop回调,但回调完全退出应用程序而不是导航到新路由。

class ProductPage extends StatefulWidget {
@override
_ProductPageState createState() => _ProductPageState();
  
}

class _ProductPageState extends State<ProductPage> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
    onWillPop: () async {
      Navigator.pushReplacementNamed(context,"homePage");
      return false;
    },
    child: Scaffold(appBar: AppBar(title: Text("Product Page"),),));
   }
  }

onMessageOpenedApp callback: onMessageOpenedApp 回调:

FirebaseMessaging.onMessageOpenedApp.listen((message) {
    print("ON MESSAGE OPENED");
    Navigator.pushNamed(context,"productsPage");
  });

The expected routing behaviour is close to this video below.预期的路由行为接近于下面的视频。 Consider this navigation from quick action of the app, the settings app was not running in the background.从应用程序的快速操作考虑此导航,设置应用程序未在后台运行。 I tap on a quick action, I get navigated to a specific screen, and upon a back button gesture or pressing the back button on the app bar, I get navigated to the home page of the app.我点击一个快速操作,导航到一个特定的屏幕,然后通过后退按钮手势或按下应用栏上的后退按钮,我导航到应用程序的主页。

Expected routing 预期路由

you could try saving a backstack like here and adding it manually when the user enters via the push notification.您可以尝试像这里一样保存一个后台堆栈,并在用户通过推送通知输入时手动添加它。
Try debugging your app in this state. My guess is, that you don't have a full backstack opening the app via push notification.尝试在此 state 中调试您的应用程序。我的猜测是,您没有通过推送通知打开应用程序的完整后台堆栈。

Maybe this helps: https://medium.com/androiddevelopers/multiple-back-stacks-b714d974f134也许这有帮助: https://medium.com/androiddevelopers/multiple-back-stacks-b714d974f134

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM