Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List != List<int> != List<String> != List<dynamic> How do i make sure if type == list returns true in dart



listType(example) {
  var x = example.runtimeType;
  if (x == List) { 
    return true;
  } else {
    return false;
  }
}

print(listType([1, 2, 3, 4]));

You can swap swap x==List with x==List< int> and see the difference!!!

How do i make it so that runtimeType always returns true as long as the return type is a list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to check the type use is and do not use runtimeType because it make x a type not list<int>, like this:

listType(example) {
  
  if (example is List) { //<--- here
    return true;
  } else {
    return false;
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading