TypeDefinition.fromDynamic constructor
TypeDefinition.fromDynamic(
- dynamic obj,
- Node? astNode
Implementation
factory TypeDefinition.fromDynamic(dynamic obj, Node? astNode) {
bool isAmbiguous = false;
final type = getTypeName(obj);
if (type == 'List') {
List<dynamic> list = obj;
String elemType;
if (list.length > 0) {
elemType = getTypeName(list[0]);
for (dynamic listVal in list) {
final typeName = getTypeName(listVal);
if (elemType != typeName) {
isAmbiguous = true;
break;
}
}
} else {
// when array is empty insert Null just to warn the user
elemType = "Null";
}
return new TypeDefinition(type,
astNode: astNode, subtype: elemType, isAmbiguous: isAmbiguous);
}
return new TypeDefinition(type, astNode: astNode, isAmbiguous: isAmbiguous);
}