android - 导航在 Firebase Messaging Flutter 中不起作用

标签 android ios flutter firebase-cloud-messaging

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

我的有效负载

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}}

  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

最佳答案

添加一个 bool 标志并在构建完成后将其设置为 true,如下所示

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

并在 onLaunch 中使用此计时器

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

关于android - 导航在 Firebase Messaging Flutter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59351696/

相关文章:

android - 振铃状态 拨出电话

android - 为 Android 应用程序客户端加密和解密数据

ios - UITextView KeyboardAppearance 属性设置 UIKeyboardAppearanceDark

通知中心未列出 iOS5 应用程序

ios - iPhone 可以在没有 Watch App 的情况下从 Watch 检索加速度计数据吗?

dart - Flutter/flutter_webview_plugin => 在向下/向上滚动时隐藏/显示 AppBar + BottomNavigationBar

firebase - 从Firebase中选择多个字段

android - SearchView on support.v7.appcompat 库问题 : default 9-patch background not renders properly

user-interface - Flutter - 找不到 TextField "textAlign"属性

android - 小部件纵横比 1 :1 (square)