Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 当我的应用程序终止时,是否有方法执行firebase后台消息中的代码?_Flutter_Dart_Firebase Cloud Messaging - Fatal编程技术网

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);
}