I have read a snapshot from Firebase, and am trying to extract the value from a node that is a list of strings.
When I do this:
List<String> answers = snapshot.value["answers"] as List<String>;
With the above I get a runtime error saying:
type
'List<dynamic>'
is not a subtype of type'List<String>'
in type cast
But somehow these two approaches below both work:
List<String> answers = List<String>.from(snapshot.value["answers"])
Or this:
List<String> answers = snapshot.value["answers"].cast<String>()
What is the difference between the first and the other two constructs, and why can't I cast the List<dynamic>
to a List<String>
with the as
casting operation?