I'm looking for a way to compare two types in Dart, and get True when they are the same.
I have a method:
SomeItemType exampleMethod<SomeItemType>(Map<String, dynamic> value) {
if (SomeItemType.toString() == 'BuiltMap<String, String>') {
return BuiltMap<String, String>.from(value) as SomeItemType;
}
// (...)
}
in which I must check if the type-parameter SomeItemType is actually equal to the type BuiltMap<String, String> or not.
The only way I found so far is the above string comparions, which is not too elegant in my opinion.
I have tried to following solutions, but they did not work out for me:
SomeItemType is BuiltMap<String, String>
// returns False
SomeItemType == BuiltMap<String, String>
// error: The operator '<' isn't defined for the type 'Type'.
BuiltMap<String, String> is SomeItemType
// error: The operator '<' isn't defined for the type 'Type'.
exampleMethod.