I am trying to add a contact to the phone from a json data in flutter.
I have used 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".
Could someone show the correct method of using this package and adding a contact.
My code is
onSaved: (val) =>
setState(() => _user.phones = val)),
As mentioned in the docs , phones is an Iterable
of Item
, not an unique String
:
// Phone numbers
Iterable<Item> phones = [];
where Item
is a basic key
/ value
object.
You need to format your val
this way:
onSaved: (val) =>
setState((){
_user.phones = []..add(Item.fromMap({'label': 'work', 'value': val})); // Set the label of your choice
});
),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.