【问题标题】:Flutter/Dart - Instance member 'displayNotification' can't be accessed using static accessFlutter/Dart - 无法使用静态访问访问实例成员“displayNotification”
【发布时间】:2021-08-09 09:10:30
【问题描述】:

我在一个名为 FCMConfig 的 Flutter 插件中使用 firebaseMessagingBackgroundHandler

以前以下代码以前可以工作。

Future<void> firebaseMessagingBackgroundHandler(
    RemoteMessage _notification) async {
  print('Handling a background message: ${_notification.data["title"]}');
  String fcmname = _notification.data["name"];
  String fcmtitle = _notification.data["title"];
  String fcmmessage = _notification.data["message"];
  String title = _notification.data["title_key"];
FCMConfig.displayNotification(title: fcmtitle, body:fcmname);
}

但在对 2.1.2 最低 SDK 进行一些更新后,我开始收到此错误;

 Instance member 'displayNotification' can't be accessed using static access.

我该如何解决这个问题?

【问题讨论】:

  • FCMConfig 定义在哪里?该错误表明您需要创建它的一个实例。
  • 来自 dart 包 - class FCMConfig extends FCMConfigInterface { static FCMConfig get instance => FCMConfig(); @override Future getInitialMessage() async { if (!kIsWeb) { var intial = await LocaleNotificationManager.getInitialMessage();如果(初始!= null)返回初始; } 返回等待 FirebaseMessaging.instance.getInitialMessage(); }
  • 也许你需要获取它的一个实例
  • 喜欢这个? FCMConfig firebaseconfig = FCMConfig.instance;

标签: flutter dart firebase-cloud-messaging instance


【解决方案1】:

根据documentation,你应该这样做:

Future<void> firebaseMessagingBackgroundHandler(
RemoteMessage _notification) async {
   print('Handling a background message: ${_notification.data["title"]}');
   String fcmname = _notification.data["name"];
   String fcmtitle = _notification.data["title"];
   String fcmmessage = _notification.data["message"];
   String title = _notification.data["title_key"];
   FCMConfig().displayNotification(title: fcmtitle, body:fcmname); // <---
}

你忘记了括号 ()。

【讨论】:

    猜你喜欢
    • 2021-03-22
    • 2020-01-03
    • 1970-01-01
    • 2020-11-29
    • 2019-06-22
    • 2021-08-19
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多