title: Use nested maps to retrieve and save data to Firebase - Flutter
body: <p>I have three models I'm working with to retrieve and write data to my Cloud Firestore.</p>
  <pre><code>//Sales model
  class Sales {
    String id;
    String userId;
    SalesDetails salesDetails;
    Timestamp createdAt;
    Timestamp updatedAt;
  
    Sales();
  
    Sales.fromMap(Map&lt;String, dynamic&gt; data) {
      id = data['id'];
      userId = data['user_id'];
      salesDetails = SalesDetails.fromMap(data['sales_details']);
      createdAt = data['created_at'];
      updatedAt = data['updated_at'];
    }
  
    Map&lt;String, dynamic&gt; toMap() {
      return {
        'id': id,
        'user_id': userId,
        'sales_details': salesDetails,
        'created_at': createdAt,
        'updated_at': updatedAt,
      };
    }
  }
  </code></pre>
  <p>//SalesDetails model</p>
  <pre><code>class SalesDetails {
    String id;
    PurchasedItems purchaseItems;
    String bankTransferSenderName;
    String chequeInfo;
    String creditPayLaterInfo;
    String customerId;
    String customerFirstName;
    String customerLastName;
    double subTotalAmount;
    double totalAmount;
    double taxesDue;
    bool isComplete;
    Timestamp createdAt;
    Timestamp updatedAt;
  
    SalesDetails();
  
    SalesDetails.fromMap(Map&lt;String, dynamic&gt; data) {
      id = data['id'];
      purchaseItems = PurchasedItems.fromMap(data['purchased_items']);
      bankTransferSenderName = data['bank_transfer_sender_name'];
      chequeInfo = data['cheque_info'];
      creditPayLaterInfo = data['credit_pay_later_info'];
      customerId = data['customer_id'];
      customerFirstName = data['customer_first_name'];
      customerLastName = data['customer_last_name'];
      subTotalAmount = data['sub_total_amount'];
      totalAmount = data['total_amount'];
      taxesDue = data['taxes_due'];
      isComplete = data['is_complete'];
      createdAt = data['created_at'];
      updatedAt = data['updated_at'];
    }
  
    Map&lt;String, dynamic&gt; toMap() {
      return {
        'id': id,
        'purchased_items': purchaseItems,
        'bank_transfer_sender_name': bankTransferSenderName,
        'cheque_info': chequeInfo,
        'credit_pay_later_info': creditPayLaterInfo,
        'customer_id': customerId,
        'customer_first_name': customerFirstName,
        'customer_last_name': customerLastName,
        'sub_total_amount': subTotalAmount,
        'total_amount': totalAmount,
        'taxes_due': taxesDue,
        'is_complete': isComplete,
        'created_at': createdAt,
        'updated_at': updatedAt,
      };
    }
  }
  </code></pre>
  <p>//PurchasedItem model</p>
  <pre><code>class PurchasedItems {
    String itemId;
    String itemName;
    String itemDescription;
    int itemQuantity;
  
    PurchasedItems();
      
    PurchasedItems.fromMap(Map&lt;String, dynamic&gt; data) {
      itemId = data['item_id'];
      itemName = data['item_name'];
      itemDescription = data['item_description'];
      itemQuantity = data['itemQuantity'];
    }
  
    Map&lt;String, dynamic&gt; toMap() {
      return {
        'id': itemId,
        'user_id': itemName,
        'item_quantity': itemQuantity,
        'item_description': itemDescription,
      };
    }
  }
  </code></pre>
  <p>After watching the official Firestore videos on Maps vs Arrays vs Collection/documents, I've decided that sub collections / documents might just be the best for me due to how I am to display the information on my app.</p>
  <ol>
  <li>my toMap and fromMap methods, are they rightly implemented?</li>
  <li>Is this nested too deep?</li>
  <li>Should I leave Sales details and purchase items as maps or are they fine as their own classes?</li>
  <li>Is there a better way to my current implementation? What's the recommended standard of working with models who depends on other class models?</li>
  </ol>
  <p>Thanks.</p>