ScrellaApiBaseResponse<T>.fromJson constructor
Creates a ScrellaApiBaseResponse from a decoded JSON map.
Throws FormatException if:
jsonisnull(empty body) – this is always an error.statusormessagefields 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);
}