Flutter 当我的应用程序终止时,是否有方法执行firebase后台消息中的代码?
对于我的颤振项目,我需要在应用程序终止时执行一些代码。该代码通过Flutter 当我的应用程序终止时,是否有方法执行firebase后台消息中的代码?,flutter,dart,firebase-cloud-messaging,Flutter,Dart,Firebase Cloud Messaging,对于我的颤振项目,我需要在应用程序终止时执行一些代码。该代码通过onBackgroundMessage回调中的firebase数据消息触发。当应用程序终止时,我得到了触发并打印发送消息的回调,但当我尝试添加更新联系人信息的代码()时,它失败并抛出MissingPluginException。我直接从应用程序中测试了插件,效果很好。 我知道后台回调函数不能访问函数外部的依赖项,但如果可能的话,我不知道如何让它工作。有什么建议吗 以下是函数: static Future<dynamic>
onBackgroundMessage
回调中的firebase数据消息触发。当应用程序终止时,我得到了触发并打印发送消息的回调,但当我尝试添加更新联系人信息的代码()时,它失败并抛出MissingPluginException
。我直接从应用程序中测试了插件,效果很好。
我知道后台回调函数不能访问函数外部的依赖项,但如果可能的话,我不知道如何让它工作。有什么建议吗
以下是函数:
static Future<dynamic> myBackgroundMessageHandler(
Map<String, dynamic> message) async {
print(message["data"]);
Iterable<Contact> contacts;
List<Contact> contactList;
contacts = await ContactsService.getContacts(); // it fails here
contactList = contacts.toList();
contactList.sort((a, b) =>
int.tryParse(a.identifier).compareTo(int.tryParse(b.identifier)));
print(contactList.last);
}
静态未来myBackgroundMessageHandler(
映射消息)异步{
打印(信息[“数据]);
可拆卸触点;
列出联系人名单;
contacts=等待ContactsService.getContacts();//此处失败
contactList=contacts.toList();
联系人列表。排序((a,b)=>
比较(int.tryParse(b.identifier));
打印(contactList.last);
}