isType function

bool isType(
  1. dynamic value,
  2. Type type
)

Checks whether a JSON value matches the expected Dart type.

Used internally to validate fields during parsing.

Implementation

bool isType(dynamic value, Type type) {
  if (value == null) return false;

  switch (type) {
    case int:
      return value is int;

    case double:
      return value is double || value is int;

    case String:
      return value is String;

    case bool:
      return value is bool;

    case List:
      return value is List;

    case Map:
      return value is Map;

    default:
      return true; // assume correct for custom models
  }
}