How to check Type of a Variable in Flutter

Last updated on February 10, 2022 A Goodman Loading... Post a comment

To check the type of a variable in Flutter and Dart, you can use the runtimeType property.

Example

The code:

void main(){
  var a = 'Apple';
  var b = 100;
  var c = [1, 2, 3, 4, 5];
  var d = {
    "name": "John Doe",
    "age" : 40
  };
  var e = 1.14;
  
  print(a.runtimeType);
  print(b.runtimeType);
  print(c.runtimeType);
  print(d.runtimeType); 
  print(e.runtimeType);
}

Output:

String
int
List<int>
_InternalLinkedHashMap<String, Object>
double

Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles