dataToModel<T> function

T dataToModel<T>({
  1. required dynamic data,
  2. Map<Type, dynamic>? modelDecoders,
})

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 bootstrap/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 bootstrap/decoders.dart must contain a decoder for Type: $T",
  );
  return nyloModelDecoders[T](data);
}