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;

  if (type == int) {
    return value is int;
  } else if (type == double) {
    return value is double || value is int;
  } else if (type == String) {
    return value is String;
  } else if (type == bool) {
    return value is bool;
  } else if (type == List) {
    return value is List;
  } else if (type == Map) {
    return value is Map;
  } else {
    return true; // assume correct for custom models
  }
}