9.4 C
New York
Monday, December 4, 2023

How to check Type of a Variable in Flutter

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:

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

Advertisements

Related Articles

Latest Articles