WatchEvent.fromJson constructor

WatchEvent.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json, {
  4. ClientUriConverter? clientUriConverter,
})

Implementation

factory WatchEvent.fromJson(
  JsonDecoder jsonDecoder,
  String jsonPath,
  Object? json, {
  ClientUriConverter? clientUriConverter,
}) {
  json ??= {};
  if (json is Map) {
    WatchEventType type;
    if (json.containsKey('type')) {
      type = WatchEventType.fromJson(
        jsonDecoder,
        '$jsonPath.type',
        json['type'],
        clientUriConverter: clientUriConverter,
      );
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'type');
    }
    String path;
    if (json.containsKey('path')) {
      path =
          clientUriConverter?.fromClientFilePath(
            jsonDecoder.decodeString('$jsonPath.path', json['path']),
          ) ??
          jsonDecoder.decodeString('$jsonPath.path', json['path']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'path');
    }
    return WatchEvent(type, path);
  } else {
    throw jsonDecoder.mismatch(jsonPath, 'WatchEvent', json);
  }
}