What does the "as" keyword do in Dart language

as means different things in different contexts.

It's primarily used as a type cast operator. From the Dart Language Tour:

as: Typecast (also used to specify library prefixes)

It links to an explanation of how as is also used to add a prefix to an imported library to avoid name collisions. (as was reused to do different things to avoid needing extra keywords.)


just to add the as keyword is now flagged by the linter and they prefer you to use a check like is

if (pm is Person)
  pm.firstName = 'Seth';

you can read more here https://github.com/dart-lang/linter/issues/145

Tags:

Dart

Flutter