flutter - Flutter/Dart - 无法使用静态访问访问实例成员“displayNotification”
问题描述
我firebaseMessagingBackgroundHandler
在一个名为FCMConfig
.
以前,以下代码以前有效。
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.
我怎样才能解决这个问题?
解决方案
根据文档,您应该这样做:
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); // <---
}
您忘记了括号 ()。
推荐阅读
- xml - M 尝试将 shipfromlocationref 交换为 shiptolocationref 以获取以下 XML
- optimization - 为什么 Rust 不能像 is_err() 那样优化特定错误的匹配?
- google-analytics - analytics.js 是否会受到 Google Analytics(分析)移动应用报告和旧版 Google Analytics(分析)服务 SDK 停用的影响
- netlogo - 如何在 Netlogo 中编码整除数
- excel-formula - Excel 论坛 - 将工作时间添加到日期和时间
- java - apache PropertiesConfiguration 不解析占位符
- c# - EntityFramework Core 在内存中缓存数据,保持异步操作
- javascript - Codemirror 自动完成
- sql-server - 创建在本地目录中生成 csv 文件的存储过程
- powershell - 如何将模拟的 PSCustomObject 作为 SQLConnection 参数传递