getDataValue static method

String getDataValue(
  1. DartObject dartObject,
  2. Map<String, dynamic>? target
)

获取 DartObject 数据值字符串。代码格式

Implementation

static String getDataValue(DartObject dartObject, Map<String, dynamic>? target) {
  String result = "";
  if (dartObject.isNull) {
    return result;
  }
  if (dartObject.type!.isDartCoreMap) {
    Map<DartObject?, DartObject?>? map = dartObject.toMapValue();
    result = "{";
    map?.forEach((key, value) {
      String strKey = getDataValue(key!, null);
      String strVal = getDataValue(value!, null);
      result += "\n$strKey : $strVal,";
      if (target != null) {
        target[strKey] = strVal;
      }
    });
    result += "\n}";
  } else if (dartObject.type!.isDartCoreString) {
    if (dartObject.toStringValue()!.startsWith(KEEP_NAME_PREFIX)) {
      return dartObject.toStringValue()!.substring(KEEP_NAME_PREFIX.length, dartObject.toStringValue()!.length);
    }
    return "\"${dartObject.toStringValue()}\"";
  } else if (dartObject.type!.isDartCoreList) {
    List<DartObject> list = dartObject.toListValue()!;
    result = "[";
    list.forEach((element) {
      result += "\n${getDataValue(element, null)},";
    });
    result += "\n]";
  } else if (dartObject.type!.isDartCoreInt) {
    result = "${dartObject.toIntValue()}";
  } else if (dartObject.type!.isDartCoreDouble) {
    result = "${dartObject.toDoubleValue()}";
  } else if (dartObject.type!.isDartCoreBool) {
    result = "${dartObject.toBoolValue()}";
  } else if (dartObject.type! is DynamicType) {
    result = "${dartObject.toString()}";
  } else {
    throw Exception("data value [${dartObject.type}] not support!!!");
  }
  return result;
}