thumbnail

Type test operators in Dart

Published on 29 March 2020
Last Updated on 29 March 2020

Table that describes various type test operators

Operator Description
is true if object type matches
!is false if object type matches
as used as typecast operator and prefixing libraries

Program about how to use type test operators in Dart

main(List<String> args) {
  int a = 1;

  // checks whether a is an integer
  print(a is int);
  // checks whether a is not an integer
  print(a is! int);
  // checks whether as is a string
  print(a is String);

  // casts a as a dynamic type object
  print((a as dynamic).toString().runtimeType);
}

Above program produces following output:

true
false
false
String