繁体   English   中英

Firebase 推送通知路由 flutter

[英]Firebase push notification routing flutter

我在我的应用程序上使用 firebase_messaging 设置了推送通知。 当通过推送通知从已终止的 state 打开应用程序时,我导航到特定路线 (ProductPage) 并在按下后退按钮时出现黑屏,因为导航堆栈上没有路线

当我按下应用栏的后退按钮或触发 Android 设备上的硬件后退按钮时,如何让应用导航到初始路径而不是看到黑屏?

我尝试使用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 回调:

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

预期的路由行为接近于下面的视频。 从应用程序的快速操作考虑此导航,设置应用程序未在后台运行。 我点击一个快速操作,导航到一个特定的屏幕,然后通过后退按钮手势或按下应用栏上的后退按钮,我导航到应用程序的主页。

预期路由

您可以尝试像这里一样保存一个后台堆栈,并在用户通过推送通知输入时手动添加它。
尝试在此 state 中调试您的应用程序。我的猜测是,您没有通过推送通知打开应用程序的完整后台堆栈。

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

暂无
暂无

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

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