dataToModel<T> function
Return an object from your modelDecoders using data
.
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 config/decoders.dart file");
if (modelDecoders != null && (modelDecoders.isNotEmpty)) {
assert(
modelDecoders.containsKey(T), "ModelDecoders not found for Type: $T");
return modelDecoders[T](data);
}
Nylo nylo = Backpack.instance.nylo();
Map<Type, dynamic> nyloModelDecoders = nylo.getModelDecoders();
assert(nyloModelDecoders.containsKey(T),
"Your modelDecoders variable inside config/decoders.dart must contain a decoder for Type: $T");
return nyloModelDecoders[T](data);
}