Reputation: 1
My code is the fllowing and error i get is 'String' is not a subtype of type 'List'
List<String> store=[];
void getData() async {
await for(var snapshot in _firestore.collection('users').snapshots()){
for(var phon in snapshot.documents){
store=(phon.data['Name']);
print(store);
}
} }
Upvotes: 0
Views: 76
Reputation: 1331
You get this error because in store=(phon.data['Name']);
you try to set the value of the whole list as a string. Instead you should've set only the value of one of the lists fields as a string. For example store[0]=(phon.data['Name']);
Upvotes: 0
Reputation: 705
List<String> store=[];
String name;
void getData() async {
await for(var snapshot in _firestore.collection('users').snapshots()){
for(var phon in snapshot.documents){
name=(phon.data['Name']);
print(name);
}
}
}
What you are doing is storing a String
(phon.data['Name'])
in a List
.
I have this sample code which has String
named name
and now storing Stringname
in phon.data['Name']
. you can also do the opposite.
Upvotes: 1
Reputation: 3165
Change store=(phon.data['Name'])
to store.add(phon.data['Name'])
You are trying to assign a single string (I assume that is what phon.data['Name'] is) to a List object.
Upvotes: 0