fromMap method

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

Implementation

void fromMap(Map<String, dynamic> map) {
  id = map[columnId];
  cpf = map[columnCpf];
  discountAmount = map[columnDiscountValue];
  freightAmount = map[columnFreightValue];
  feeAmount = map[columnFeeValue];
  subTotalAmount = map[columnSubTotal];
  totalAmount = map[columnTotal];
  subTotalSeparatedAmount = map[columnSubTotalSeparated];
  totalSeparatedAmount = map[columnTotalSeparated];
  maxInstallments = map[columnMaxInstallments];
  installments = map[columnInstallments];
  isDelivery = map[columnIsDelivery] == 1 ? true : false;
  deliveryTime = map[columnDeliveryTime];
  latitude = map[columnLatitude];
  longitude = map[columnLongitude];
  cep = map[columnCep];
  cpfInvoice = map[columnCpfInvoice];
  cpfPickUp = map[columnCpfPickup];
  isPickupOnly = map[columnIsPickupOnly] == 1 ? true : false;
  dealerCode = map[columnDealerCode];
  shouldTransfer = map[columnShouldTransfer] == 1 ? true : false;
  buyer = map[columnBuyer] != null
      ? Buyer.fromJson(json.decode(map[columnBuyer]))
      : null;

  // Custom objects fetching
  Iterable iItems = json.decode(map[columnItems]);
  List<CartItem> cartItems = [];
  iItems.forEach((map) {
    CartItem item = CartItem.fromJson(map);
    item.migrateToCurrentVersion();
    cartItems.add(item);
  });
  this.allItems = cartItems;

  List<String> listOfMessages = [];
  if (map[columnMessages] != null) {
    Iterable cm = json.decode(map[columnMessages]);
    cm.forEach((message) {
      listOfMessages.add(message);
    });
  }
  this.messages = listOfMessages;

  modality = (map[columnModality] == null || map[columnModality] == 'null')
      ? null
      : SellerModality.fromJson(json.decode(map[columnModality]));
  freight = (map[columnFreight] == null || map[columnFreight] == 'null')
      ? null
      : Freight.fromJson(json.decode(map[columnFreight]));
  deliveryAddress = (map[columnDeliveryAddress] == null ||
          map[columnDeliveryAddress] == 'null')
      ? null
      : UserAddress.fromJson(json.decode(map[columnDeliveryAddress]));
  seller = (map[columnSeller] == null || map[columnSeller] == 'null')
      ? null
      : Seller.fromJson(json.decode(map[columnSeller]));
  paymentMethod =
      (map[columnPaymentMethod] == null || map[columnPaymentMethod] == 'null')
          ? null
          : PaymentMethod.fromJson(json.decode(map[columnPaymentMethod]));

  if (map[columnSupportedPaymentMethods] != null) {
    Iterable pItems = json.decode(map[columnSupportedPaymentMethods]);
    List<PaymentMethodType> supportedPayments = [];
    if (pItems != null) {
      pItems.forEach((map) {
        supportedPayments.add(PaymentMethodType.values[map]);
      });
    }
    supportedPaymentTypes = supportedPayments;
  }

  voucher = map[columnVoucher] == 'null'
      ? null
      : Voucher.fromJson(json.decode(map[columnVoucher]));

  isCvvValidated = map[columnIsCvvValidated] == 1 ? true : false;
  hasFeeInstallment = map[columnHasFeeInstallment] == 1 ? true : false;

  giftsQuantityAllowed = map[columnGiftsQuantityAllowed];
  if (map[columnAvailableGiftItems] != null) {
    Iterable gItems = json.decode(map[columnAvailableGiftItems]);
    List<CartItem> giftItems = [];
    if (gItems != null) {
      gItems.forEach((map) {
        CartItem item = CartItem.fromJson(map);
        giftItems.add(item);
      });
    }
    availableGiftItems = giftItems;
  }

  changesFromLastUpdate =
      json.decode(map[columnChangesFromLastUpdate] ?? '{}');
}