【问题标题】:Navigation is not working in Firebase Messaging Flutter导航在 Firebase Messaging Flutter 中不起作用
【发布时间】:2020-04-08 15:00:57
【问题描述】:

屏幕无法在 onLaunh()onResume() firebase 消息传递方法中导航,我尝试显示本地通知以导航屏幕但仍然失败。

我的负载

onResume 有效负载======{通知:{},数据:{通知类型:视频呼叫,角色: ROLE_CONSILIER_CARIERA,google.original_priority:高, google.sent_time:1576478554401,google.delivered_priority:高, 约定: {"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"},正文:Apelul 视频节目 este activ acum pentru student,标题: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}}

  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 我也跟着做, 据我了解,为什么我得到密钥notification null 但在onMessage 我得到notification 的标题和正文。

【问题讨论】:

    标签: android ios flutter firebase-cloud-messaging


    【解决方案1】:

    像这样在构建完成后添加一个布尔标志并将其设置为真

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

    并在您的 onLaunch 中使用此计时器

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

    【讨论】:

    • 让我试试。但我已经尝试过使用全局状态和未来延迟
    • 您能否分享正确的示例,无法理解我们应该在哪里添加此代码以及它们如何相互通信。提前谢谢你。
    猜你喜欢
    • 2021-06-04
    • 2021-12-08
    • 2019-01-28
    • 2022-01-18
    • 2018-07-29
    • 2020-09-05
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多