Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read array from Firebase in Flutter [duplicate]

I have a collection defined in Firebase with different field types, such as Strings and arrays of string.

I am able to read Strings from DocumentSnapshot simply by calling:

String name = document['name'];

But how can I get List<String>? By calling

List<String> names1 = document['names'];
List<String> names2 = document['ingredients'].map((x) => x.toString())

I get following exceptions accordingly:

type 'List' is not a subtype of type 'List'
type 'MappedListIterable' is not a subtype of type 'List'

like image 493
streetturtle Avatar asked Jun 16 '18 21:06

streetturtle


Video Answer


1 Answers

It could be done simply using a named .from constructor:

List<String> names = List.from(document['names']);
like image 114
streetturtle Avatar answered Oct 09 '22 06:10

streetturtle