簡體   English   中英

在 FCM onLaunch 上防止 main.dart

[英]Prevent main.dart on FCM onLaunch

從 FCM firebase 通知的onLaunch()加載時,是否有適當的方法/flutter-firebase 指南來防止 flutter 應用程序從 main.dart 重新啟動。

我可以看到, 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);
  },
);

當您單擊 FCM 通知時,應用程序可能會從onLaunch方法啟動,並且確實會調用main.dart 我建議請嘗試在main.dart中注入fcm.configure() ,相反,您可以注入任何有狀態的小部件/屏幕,以便在單擊通知時直接調用屏幕以啟動( onLaunch )。

例如:-> main.dart -> homescreen.dart -> somescreen -> 永遠流

如果你想調用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 .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM