processValue static method

String? processValue(
  1. dynamic value,
  2. StrapiFieldQuery query
)

helper function which evaluates whether the value provided is leaf value like String, int, double, bool, DateTime or lis of these types incase the query operation is StrapiFieldQuery.includesInAnArray or StrapiFieldQuery.notIncludesInAnArray

Implementation

static String? processValue(value, StrapiFieldQuery query) {
  if (value is int || value is double || value is bool) {
    return "$value";
  }
  if (value is DateTime) {
    return "\"${value.toIso8601String()}\"";
  }
  if (value is String) {
    return '''"$value"''';
  }

  ///specific to [StrapiFieldQuery.includesInAnArray] or [StrapiFieldQuery.notIncludesInAnArray]
  if (value is List &&
      (query == StrapiFieldQuery.includesInAnArray ||
          query == StrapiFieldQuery.notIncludesInAnArray) &&
      value.isNotEmpty &&
      value.first is String) {
    return "[${value.map((e) => "\"$e\"").join(",")}]";
  }
}