How To Typecast in Flutter ‘cast’

Casting a List to another type
Dart has generic types. To put it simply, it means that when you have a container type, like a list, the type of the items inside the list is known, or they should be specified.
For example List<num>
is a list of type num
; you cannot put an apple in it.
Sometimes you want to use it as another type though, for example you have a list of teachers, but you want to have a list of people. In these cases, you need to tell dart to treat the generic type as you like it too.
For example, in this example we would like to change the type ’num’ to be treated as double.
The cast
method tells compiler to treat the list of nums, as list of doubles. And if you remove that line, it is not going to compile.