gpt4 book ai didi

flutter - 收到此错误 : Unhandled Exception: FormatException: Invalid envelope - While adding the contact

转载 作者:行者123 更新时间:2023-12-04 15:40:22 62 4
gpt4 key购买 nike

使用联系服务添加联系人时出现错误。

Contact newContact = new Contact();

newContact.givenName ="Ajay";
newContact.familyName ="abc";

newContact.phones = [Item(label: "mobile",value: "9998887771")];

await ContactsService.addContact(newContact);

最佳答案

这将解决您的问题:
处理权限的最新版本是现在permission_handler: ^5.0.1+1

    Future<void> saveContactInPhone() async {
try {

print("saving Contact");
PermissionStatus permission = await Permission.contacts.status;

if (permission != PermissionStatus.granted) {
await Permission.contacts.request();
PermissionStatus permission = await Permission.contacts.status;

if (permission == PermissionStatus.granted) {
Contact newContact = new Contact();

newContact.givenName ="Ajay";
newContact.familyName ="abc";

newContact.phones = [Item(label: "mobile",value: "9998887771")];

await ContactsService.addContact(newContact);

} else {
//_handleInvalidPermissions(context);
}
} else {
Contact newContact = new Contact();

newContact.givenName ="Ajay";
newContact.familyName ="abc";

newContact.phones = [Item(label: "mobile",value: "9998887771")];

await ContactsService.addContact(newContact);
}
print("object");

} catch (e) {
print(e);
}
}
这对我来说非常好。

关于flutter - 收到此错误 : Unhandled Exception: FormatException: Invalid envelope - While adding the contact,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57969216/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com