contains function

bool contains(
  1. dynamic value,
  2. dynamic searchValue
)

Returns true if value contains searchValue.

  • Supports String, List, and Set.
  • For strings, converts searchValue to a string before searching.
  • Returns false if value is null.
  • Throws Exception if value is not a supported type.

Implementation

bool contains(dynamic value, dynamic searchValue) {
  if (value == null) return false;
  if (value is String) return value.contains(searchValue.toString());
  if (value is List) return value.contains(searchValue);
  if (value is Set) return value.contains(searchValue);
  throw Exception("Invalid type '${value.runtimeType}' for 'contains' "
      "function. Valid types are String, List and Set.");
}