[英]Error in adding phone number to contacts_service
I am trying to add a contact to the phone from a json data in flutter.我正在尝试从 flutter 中的 json 数据向手机添加联系人。
I have used contacts_service package.我用过contacts_service package。 But I when I am trying to add the phone number to the model,"a String cant be assigned to a iterable error pops".
但是当我尝试将电话号码添加到 model 时,“无法将字符串分配给可迭代的错误弹出”。
Could someone show the correct method of using this package and adding a contact.有人可以展示使用此 package 并添加联系人的正确方法。
My code is我的代码是
onSaved: (val) =>
setState(() => _user.phones = val)),
As mentioned in the docs , phones is an Iterable
of Item
, not an unique String
:如文档中所述,phones 是
Item
的Iterable
,而不是唯一的String
:
// Phone numbers
Iterable<Item> phones = [];
where Item
is a basic key
/ value
object.其中
Item
是基本key
/ value
object。
You need to format your val
this way:您需要以这种方式格式化您的
val
:
onSaved: (val) =>
setState((){
_user.phones = []..add(Item.fromMap({'label': 'work', 'value': val})); // Set the label of your choice
});
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.