简体   繁体   English

在 FCM onLaunch 上防止 main.dart

[英]Prevent main.dart on FCM onLaunch

Is there a proper way/flutter-firebase guidelines to prevent a flutter app to re-start from main.dart when loading from onLaunch() of FCM firebase notification.从 FCM firebase 通知的onLaunch()加载时,是否有适当的方法/flutter-firebase 指南来防止 flutter 应用程序从 main.dart 重新启动。

I can see, onLaunch being triggered but soon main.dart overrides it.我可以看到, onLaunch被触发但很快 main.dart 覆盖它。

_fcm.configure(
  // Called when the app is in the foreground and we receive a push notification
  onMessage: (Map<String, dynamic> message) async {
    print('onMessage: $message');
  },
  // Called when the app has been closed comlpetely and it's opened
  // from the push notification.
  onLaunch: (Map<String, dynamic> message) async {
    print('onLaunch: $message');
    _serialiseAndNavigate(message); //THIS WORKS , BUT SUDDENLY main.dart KICKS IN .
  },
  // Called when the app is in the background and it's opened
  // from the push notification.
  onResume: (Map<String, dynamic> message) async {
    print('onResume: $message');
    _serialiseAndNavigate(message);
  },
);

When you click on the FCM notification, app is likely to be launch from onLaunch method and it does invoke the main.dart .当您单击 FCM 通知时,应用程序可能会从onLaunch方法启动,并且确实会调用main.dart I would suggest please try to inject fcm.configure() not in main.dart , instead you can inject in whatever stateful widget/screen you want to invoke the screen directly to launch when notification gets clicked ( onLaunch ).我建议请尝试在main.dart中注入fcm.configure() ,相反,您可以注入任何有状态的小部件/屏幕,以便在单击通知时直接调用屏幕以启动( onLaunch )。

ex:-> main.dart -> homescreen.dart -> somescreen -> forever flow例如:-> main.dart -> homescreen.dart -> somescreen -> 永远流

if you want to invoke onLaunch to open homescreen.dart, run the fcm.configure() to homescreen.dart -> initState如果你想调用onLaunch打开 homescreen.dart,运行fcm.configure()到 homescreen.dart -> initState

Remember it will also run main.dart at first as flutter starts the flow of the app from main.dart itself, you cannot change it I guess, but on notification tap it will not open main.dart, instead it will launch homescreen.dart. Remember it will also run main.dart at first as flutter starts the flow of the app from main.dart itself, you cannot change it I guess, but on notification tap it will not open main.dart, instead it will launch homescreen.dart .

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

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