dataToModel<T> function
Return an object from your modelDecoders using data.
Decodes the same way API responses do, so a OneOf or other NyDecoder in your modelDecoders works here too.
Implementation
T dataToModel<T>({required dynamic data, Map<Type, dynamic>? modelDecoders}) {
assert(
T != dynamic,
"You must provide a Type from your modelDecoders from within your bootstrap/decoders.dart file",
);
if (modelDecoders != null && (modelDecoders.isNotEmpty)) {
assert(
findDecoder(T, modelDecoders) != null,
"ModelDecoders not found for Type: $T",
);
return decodeWithDecoders(data, modelDecoders, type: T);
}
Nylo nylo = Backpack.instance.nylo();
Map<Type, dynamic> nyloModelDecoders = nylo.getModelDecoders();
assert(
findDecoder(T, nyloModelDecoders) != null,
"Your modelDecoders variable inside bootstrap/decoders.dart must contain a decoder for Type: $T",
);
return decodeWithDecoders(data, nyloModelDecoders, type: T);
}