What is the difference among .cast() and List.from() and List.castFrom()


List foo -> List bar
I can use three method

1.List<MyClass> bar = foo.cast<MyClass>()
2.List<MyClass> bar = List.castFrom(foo)
3.List<MyClass> bar = List.from(foo)

What is the difference?


  1. cast<MyClass>: Returns the view (Immutable List, altering order of the list won’t be reflected in original list) of the List containing instances of MyClass type. Please follow.
  2. castFrom(foo): Adapts source (foo) to be a List. Please follow
  3. from(foo): Creates a List from Iterable (foo) objects provided in the Argument. Please follow

Answered By – Zain Ul Abideen

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *