0

If I receive real-time data, sometimes the type is List , and sometimes the type is Map<String, dynamic>, and on each type, I want to perform different operations; how can I differentiate them?

cys
  • 1
  • 2
  • You can check for the instance type at runtime (if (data is List) or if(data is Map) but if you were using Firestore and getting real-time data through the stream, it is easy to distinguish because of the type of query (against a collection or against a single document). – Roman Jaquez Feb 25 '22 at 21:29

1 Answers1

0

you can use this function , it return 0--> when given argument is List,1 --> when given argument is Map, 2--> when given argument is no List or Map

int  isListOrMap(var d){
  if(d is List){
    return 0;
  }
  if(d is Map){
    return 1;
  }
  return 2;
}