Pgto.fromMap constructor

Pgto.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory Pgto.fromMap(Map<String, dynamic> map) {
  if (map.containsKey('MP')) {
    final List<MP> listMP = [];

    if (map['MP'].runtimeType.toString() != 'List<dynamic>') {
      listMP.add(MP.fromMap(map['MP']));
    } else {
      listMP.addAll(List<MP>.from(map['MP']?.map((x) => MP.fromMap(x))));
    }
    return Pgto(
      formas: map['MP'] != null ? listMP : null,
      vTroco: map['vTroco'],
    );
  } else if (map.containsKey('detPag')) {
    if (map['detPag'].runtimeType.toString() == 'List<dynamic>') {
      List<MP> listMP = [];
      for (var pag in map['detPag']) {
        listMP.add(MP.fromMap(pag));
      }
      return Pgto(
        formas: listMP.isNotEmpty ? listMP : null,
        vTroco: map['vTroco'],
      );
    } else {
      final listMP = [MP.fromMap(map['detPag'])];
      return Pgto(
        formas: map['detPag'] != null ? listMP : null,
        vTroco: map['vTroco'],
      );
    }
  } else {
    return Pgto();
  }
}