Flutter/Dart - 无法使用静态访问访问实例成员 'displayNotification'

Flutter/Dart - Instance member 'displayNotification' can't be accessed using static access

我在名为 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.

我该如何解决这个问题?

根据 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); // <---
}

您忘记了括号 ()。