firebase - Flutter 2.0 - 没有为类型 'configure' 定义方法 'FirebaseMessaging'

标签 firebase flutter messaging

我是 flutter 的新手。我刚刚将一个为我构建的项目升级到 flutter 2.0,我不确定如何解决这个特定问题。我用谷歌搜索并找到了例子。我知道这里有改进,可能会解决我的应用程序面临的问题之一。但我不知道如何调整这个特定的代码部分,因为它比我在网上找到的任何例子都要复杂。希望有人能指出我正确的方向。

void initFCMNotification() {
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        mapEntry = message;
        String type =
            message['Notificationtype'] ?? message['data']['Notificationtype'];
        print("notification onMessage $type");

        if (type == '5' || type == '11' || type == '3') {
          Function reload = context.read<EventsProvider>().reload;
          Future.delayed(Duration(seconds: 1), () {
            reload(true);
          });
        } else if (type == '4') {
          var notification = getNotification(message);
          nav.currentState.push(MaterialPageRoute(
              builder: (context) => MeetAgainScreen(notification)));
        }
        if (type != '11') {
          if (Platform.isIOS) {
            notiType = message['Notificationtype'];
            print('isIOS on message ${message['aps']['alert']['title']}');
            if (type == "0") {
              reloadData(type, message);
            } else {
              showSilentNotification(flutterLocalNotificationsPlugin,
                  title:
                      "${message['title'] ?? message['aps']['alert']['title'] ?? message['notification']['title'] ?? ''}",
                  payload: "${message['Notificationtype'] ?? ''}",
                  body:
                      "${message['body'] ?? message['aps']['alert']['body'] ?? message['notification']['body'] ?? ''}",
                  id: 1);
            }
          } else if (Platform.isAndroid) {
            notiType = message['data']['Notificationtype'];

            print('Android on message /*${message['data']['body']}*/');
            if (type == "0") {
              reloadData(type, message);
            } else {
              showSilentNotification(flutterLocalNotificationsPlugin,
                  title:
                      "${message['data']['title'] ?? message['notification']['title'] ?? ''}",
                  payload: "${message['data']['Notificationtype'] ?? ''}",
                  body:
                      "${message['data']['body'] ?? message['notification']['body'] ?? ''}",
                  id: 1);
            }
          }
        }

最佳答案

从 8.0.0-dev.1 版本开始,configure()已删除以支持调用返回 Streams 的特定静态方法.
您应该使用 FirebaseMessaging.onMessage() , FirebaseMessaging.onMessageOpenedApp()反而。
这里的例子

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
        ...
});
您可以在此找到更多信息 pub's changelog .

关于firebase - Flutter 2.0 - 没有为类型 'configure' 定义方法 'FirebaseMessaging',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66595217/

相关文章:

Flutter floatingActionButton 在模态底部(无脚手架)

java - 如何在使用 apache qpid 时处理 jms 消息传递中的生产者流控制

java - 当同一网站的另一个 session 并行完成一些工作时,如何使网页自动重新加载?

Firebase 报告选项

ios - Firebase 作为发票的分布式数据库同步引擎,断开连接?

android - 使用实现或 api 时,Firebase 性能配置因 v1.1.2 而失败

带有图像的 Flutter 自定义 radio 小部件

java - 处理 MVVM 架构中的输入和 Firebase 错误

dart - 持久化Flutter小部件在内存中

c# - 使用 C# 进行消息传递的用途