Dart Map runtimeType
Syntax & Examples


Syntax of Map.runtimeType

The syntax of Map.runtimeType property is:

 Type runtimeType 

This runtimeType property of Map a representation of the runtime type of the object.

Return Type

Map.runtimeType returns value of type Type.



✐ Examples

1 Get the runtime type of a number

In this example,

  1. We declare a variable named number with the value 42.
  2. We use the runtimeType property of number to get its runtime type.
  3. We print the runtime type to standard output.

Dart Program

void main() {
  var number = 42;
  Type type = number.runtimeType;
  print('The runtime type of $number is $type');
}

Output

The runtime type of 42 is int

2 Get the runtime type of a string

In this example,

  1. We declare a variable named text with the value 'Hello, world!'.
  2. We use the runtimeType property of text to get its runtime type.
  3. We print the runtime type to standard output.

Dart Program

void main() {
  var text = 'Hello, world!';
  Type type = text.runtimeType;
  print('The runtime type of $text is $type');
}

Output

The runtime type of Hello, world! is String

3 Get the runtime type of a boolean

In this example,

  1. We declare a variable named condition with the value true.
  2. We use the runtimeType property of condition to get its runtime type.
  3. We print the runtime type to standard output.

Dart Program

void main() {
  var condition = true;
  Type type = condition.runtimeType;
  print('The runtime type of $condition is $type');
}

Output

The runtime type of true is bool

Summary

In this Dart tutorial, we learned about runtimeType property of Map: the syntax and few working examples with output and detailed explanation for each example.