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,
- We declare a variable named
number
with the value 42. - We use the
runtimeType
property ofnumber
to get its runtime type. - 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,
- We declare a variable named
text
with the value 'Hello, world!'. - We use the
runtimeType
property oftext
to get its runtime type. - 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,
- We declare a variable named
condition
with the valuetrue
. - We use the
runtimeType
property ofcondition
to get its runtime type. - 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.