How to check Type of a Variable in Flutter

Last updated on November 3, 2020 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
JSArray<int>
JsLinkedHashMap<String, Object>
double
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles