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'
It could be done simply using a named .from
constructor:
List<String> names = List.from(document['names']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With