如何导航到特定的屏幕时,点击Firebase推送通知时,应用程序处于终止状态在 Flutter ?

iq0todco  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(133)

对于导航到特定的屏幕时,应用程序被终止,我使用getInitialMessage方法和调用函数命名_但导航并没有发生。当应用程序终止时,我应该使用onSelectNotification方法来导航吗?
对于导航到特定的屏幕时,应用程序被终止,我使用getInitialMessage方法和调用函数命名_但导航并没有发生。当应用程序终止时,我应该使用onSelectNotification方法来导航吗?public void run(){

getIt.registerSingleton<SharedPreferences>(
        await SharedPreferences.getInstance());
    FirebaseMessaging.instance
        .getInitialMessage()
        .then((RemoteMessage? message) async {
      // SharedPreferences shared = await SharedPreferences.getInstance();
      // String? token = await getIt<SharedPreferences>().getString("token");
      if (message != null) {
        _handleMessage(message);
      }
    });

    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
      _handleMessage(message);
    });
    AndroidInitializationSettings initializationSettingsAndroid =
        AndroidInitializationSettings('@mipmap/ic_launcher');
    DarwinInitializationSettings initializationSettingsIOS =
        DarwinInitializationSettings();
    InitializationSettings initializationSettings = InitializationSettings(
        android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
    flutterLocalNotificationsPlugin.initialize(
      initializationSettings,
    );
  }
//   static Future<void> initialize(FlutterLocalNotificationsPlugin flutterlocalplugin)async{
//   flutterlocalplugin.initialize(initializationSettings,on)
// }

  //show notification

  void _handleMessage(RemoteMessage message) {
    if (message.data != null || message.data["entityid"] != null) {
      bool checkid = true;
      getIt<SharedPreferences>().setBool('checkId', checkid);

      String entityid = message.data['entityid'];
      getIt<SharedPreferences>().setString('entityid', entityid);

      if (message.data['module'] == 'Invoices' &&
          message.data['target'] != null) {
        String targetid = message.data['target'];
        getIt<SharedPreferences>().setString('targetid', targetid);
        bool checkid = true;

        navigatorKey.currentState!.pushNamed(upcomingDetails);
      } else if (message.data['module'] == 'Invoices' &&
          message.data['entityid'] != null &&
          message.data['target'] == null) {
        String entityid = message.data['entityid'];

        navigatorKey.currentState!.pushNamed(landing);

        var targetid = null;
        getIt<SharedPreferences>().setString('targetid', targetid);
      }

      // else if (message.data['module'] == 'Invoices' &&
      //     message.data['target'] == null) {
      //   navigatorKey.currentState!.pushNamed(InvoiceScreen);
      // }
      else if (message.data['module'] == 'Payments') {
        navigatorKey.currentState!.pushNamed(totalPayment);
      } else if (message.data['module'] == 'KYC' &&
          message.data['entityid'] != null) {
        String entityid = message.data['entityid'];

        getIt<SharedPreferences>().setString('companyId', entityid);

        navigatorKey.currentState!.pushNamed(kycVerification);
      } else if (message.data['module'] == 'Entities') {
        navigatorKey.currentState!.pushNamed(InvoiceScreen);
      }
    }
  }
9udxz4iz

9udxz4iz1#

FirebaseMessaging.instance.getInitialMessage().then((message){
您的代码

});

相关问题