FieldInfo.fromMapEntry constructor

FieldInfo.fromMapEntry(
  1. MapEntry<DartObject?, DartObject?> e
)

Implementation

factory FieldInfo.fromMapEntry(MapEntry<DartObject?, DartObject?> e) {
  if (e.value == null) {
    throw UnsupportedError("'null' is not supported as value!");
  }

  var type = e.value!.type.toString();
  var name = e.key!.toStringValue()!;
  var value = e.value!;

  if ((type.contains("List") && type.contains("String")) ||
      (type == "List<dynamic>" && value.toListValue()?.isEmpty == true)) {
    type = "StringList";
    final list = (value.getField("values") ?? value).toListValue();
    final valueStr =
        "[${list?.map((e) => "'${e.toStringValue()}'").join(",") ?? ""}]";
    return FieldInfo(type, name, valueStr, false);
  }

  if (value.type?.element?.kind.displayName == "enum") {
    return FieldInfo(type, name,
        "$type.${value.getField("_name")!.toStringValue()!}", true);
  }

  if (!_supportedTypes.contains(type)) {
    _throwUnsupportedError(name, type);
  }
  return FieldInfo(
      type, name, value.toString().split("(").last.split(")").first, false);
}