ScrellaApiBaseResponse<T>.fromJson constructor

ScrellaApiBaseResponse<T>.fromJson(
  1. Map<String, dynamic>? json,
  2. T deserialize(
    1. dynamic data
    )
)

Creates a ScrellaApiBaseResponse from a decoded JSON map.

Throws FormatException if:

  • json is null (empty body) – this is always an error.
  • status or message fields are missing or have the wrong type.

The deserialize callback receives the exact, unmodified value of the data field from the response (which can be null, a Map, a List, a primitive, etc.) and is responsible for converting it into a non‑null instance of T.

Implementation

factory ScrellaApiBaseResponse.fromJson(
  Map<String, dynamic>? json, // non‑nullable – null JSON is an error
  T Function(dynamic data) deserialize, // ← now accepts any JSON value
) {
  final status = json?['status'] ?? false;
  final message = json?['message'] ?? "";

  final dynamic rawData = json?['data'];
  final T? data = rawData == null ? null : deserialize(rawData);

  return ScrellaApiBaseResponse(status: status, message: message, data: data);
}