我使用下面一行代码进行Firebase消息传递配置和Flutter 通知配置,但是现在在集成到最新版本的Firebase消息传递后,它给出了错误

代码行

 messaging.configure(onMessage: (Map<String, dynamic> message){}

DART分析中出错

error: The method 'configure' isn't defined for the type 'FirebaseMessaging'. 

推荐答案

请判断以下示例.

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/firebase_messaging/example/lib/main.dart

  @override
  void initState() {
    super.initState();
    FirebaseMessaging.instance
        .getInitialMessage()
        .then((RemoteMessage message) {
      if (message != null) {
        Navigator.pushNamed(context, '/message',
            arguments: MessageArguments(message, true));
      }
    });

    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      RemoteNotification notification = message.notification;
      AndroidNotification android = message.notification?.android;

      if (notification != null && android != null) {
        flutterLocalNotificationsPlugin.show(
            notification.hashCode,
            notification.title,
            notification.body,
            NotificationDetails(
              android: AndroidNotificationDetails(
                channel.id,
                channel.name,
                channel.description,
                // TODO add a proper drawable resource to android, for now using
                //      one that already exists in example app.
                icon: 'launch_background',
              ),
            ));
      }
    });

    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      print('A new onMessageOpenedApp event was published!');
      Navigator.pushNamed(context, '/message',
          arguments: MessageArguments(message, true));
    });
  }

Flutter相关问答推荐

我如何才能收到每天重复的预定通知?

Android Emulator冻结,但在调整窗口大小时解冻

Flutter 中不存在URI的目标

无法将Flutter 连接到Firebase

在创建肘部并使用冻结时,无法使用中的Copy With方法

Riverpod状态管理-在调用请求时更新用户界面

Flutter creating Constant.dart InputDecoration section put pass in hintText

使用GO_ROUTER在模式内导航

关闭模式,但再次打开时微件条件相同

UI中的Flutter 下拉列表值未更改

为什么我的页面控制器在使用Riverpod时没有更改我的页面视图?

Flutter Android Google Sign-in error:ApiException:10在确认软件包名称、SHA-1 fingerprint 和设置同意页面后出现异常

没有为类型 'Widget' 定义运算符 '[]' .try 定义运算符[]

Flutter url_launcher 插件抛出java.lang.IllegalArgumentException:接收器未注册:io.flutter.plugins.urllauncher.WebViewActivity

如何在 Flutter 中将列小部件添加到行小部件?

使用 onPressed 切换到另一个屏幕无法正常工作

type '_InternalLinkedHashMap' 不是使用 http 包的'String' 类型的子类型

Flutter Firebase:如何判断返回值是否是特定对象

如何从dart 中的当前日期时间中减go 1 天?

Flutter 在滚动期间保持某些元素固定?