evaluateCondition method

bool evaluateCondition(
  1. Map spec
)

Evaluates an "OperatorCondition" Property.

Implementation

bool evaluateCondition(Map spec) {
  final type = spec["_type"] ?? "";
  bool result;
  switch (type) {
    case "NullOrEmpty":
      final not = parseBool(spec["not"]);
      result = false;
      final value = spec["value"];
      if (value == null) {
        result = true;
      } else if (value is List) {
        result = value.isEmpty;
      } else if (value is Map) {
        result = value.isEmpty;
      } else if (value is String) {
        result = value.isEmpty;
      }
      result = not ? !result : result;
      break;
    case "OperatorCondition":
      result =
          evaluateOperator(spec["left"], spec["operator"], spec["right"]);
      break;
    default:
      result = true;
      break;
  }

  if (result && spec["and"] != null) {
    result = evaluateCondition(spec["and"]);
  }
  if (!result && spec["or"] != null) {
    result = evaluateCondition(spec["or"]);
  }
  return result;
}