简体   繁体   English

导航在 Firebase Messaging Flutter 中不起作用

[英]Navigation is not working in Firebase Messaging Flutter

The screen is not navigating in onLaunh() and onResume() methods of firebase messaging, And I tried to show local notification to navigate scree but still fail.屏幕未在onLaunh()消息传递的onLaunh()onResume()方法中导航,我尝试显示本地通知以导航屏幕,但仍然失败。

My Payload我的有效载荷

onResume payload======{notification: {}, data: {notification_type: VideoCalling, role: ROLE_CONSILIER_CARIERA, google.original_priority: high, google.sent_time: 1576478554401, google.delivered_priority: high, appointment: {"video_duration":"0","mod_desfasurare":"3","observatii_destinatar":"","initiator":"204","observatii_initiator":"chdh","data_sfarsit_programare":"2019-12-14 12:00:00","created_by_user":"204","data_inceput_programare":"2019-12-14 11:00:00","status_destinatar":"1","status_initiator":"1","descriere":"chhxsh","destinatar":"246","tip":"0","id":"241","data_adaugarii":"2019-12-13 15:56:39","titlu":"test 13 dc","disponibilitate":"346"}, body: Apelul video programat este activ acum pentru student, title: Escouniv, click_action: FLUTTER_NOTIFICATION_CLICK, google.message_id: 0:1576478554409777%dd3b8f6edd3b8f6e, collapse_key: com.sys.escouniv, google.ttl: 2419200, from: 347273381579, id: 50, status: done}} onResume payload======{notification: {}, data: {notification_type: VideoCalling, role: ROLE_CONSILIER_CARIERA, google.original_priority: high, google.sent_time: 1576478554401, google.delivered_priority: high,约会: {"video_duration" "0","mod_desfasurare":"3","observatii_destinatar":"","initiator":"204","observatii_initiator":"chdh","data_sfarsit_programare":"2019-12-14 12:00:00 ","created_by_user":"204","data_inceput_programare":"2019-12-14 11:00:00","status_destinatar":"1","status_initiator":"1","descriere":"chhxsh" ,"destinatar":"246","tip":"0","id":"241","data_adaugarii":"2019-12-13 15:56:39","titlu":"test 13 dc ","dissponibilitate":"346"}, body: Apelul video programat este activ acum pentru student, title: Escouniv, click_action: FLUTTER_NOTIFICATION_CLICK, google.message_id: 0:1576478554409777%dd3b8.keysf6ediv, ttl: 2419200, from: 347273381579, id: 50, status: done}}

  onLaunch: (Map<String, dynamic> msg) async {
        Log.e('onLaunch====== ', msg);
        Log.e('onLaunch data====== ', msg['data']);
       // showNotification(msg);
        _navigateToItemDetail(msg);
      /*  Future.delayed(
            const Duration(seconds: 4),
                () =>    Navigator.push(
          context,
          new MaterialPageRoute(builder: (context) => new StudentTutorials(user:UserType.Student,)),
        ));*/

      },

@Anand Saga here I followed the same thing , As i understand why I'm getting key notification null but in onMessage i'm getting notification with title and body. @Anand Saga 在这里我遵循了同样的事情,据我所知,为什么我的关键notification空,但在onMessage我收到了带有标题和正文的notification

Add one bool flag and set it true after build complete like this添加一个 bool 标志并在构建完成后将其设置为 true

WidgetsBinding.instance.addPostFrameCallback((_){ flag = true; });

And use this timer inside your onLaunch并在您的onLaunch使用此计时器

Timer.periodic(Duration(seconds: 1), (timer){
  if(flag) {
    timer.cancel();
    doNavigation();
  }
});

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

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