FIrebase setData kef-value sequence not preserved

Viewed 33

I am trying to add data in firebase as the key-value sequence I have provided in setData.

create({Function onAdded, Function onDuplicate}) async {
    bool temp = await lrCheck();
    if (temp) {
      await fireStore.collection("Admin").document(TextFieldData.lrNO).setData(
        {
          "lrNO": TextFieldData.lrNO,
          "departureDate": TextFieldData.departureDate,
          "partyName": TextFieldData.partyName,
          "vehicleNo": TextFieldData.vehicleNo,
          "origin": TextFieldData.origin,
          "destination": TextFieldData.destination,
          "quantity": TextFieldData.quantity,
          "invoiceNo": TextFieldData.invoiceValue,
          "invoiceValue": TextFieldData.invoiceValue,
          "arrivalDate": TextFieldData.arrivalDate,
          "materialType": TextFieldData.materialType,
          "phoneNo": TextFieldData.phoneNo,
        },
      ).whenComplete(onAdded());

But the data stored in firebase is in alphabatical orer of keys plzz help. ex:

arrivalDate: value
destination: value
and so on ....
2 Answers

The data in the firebase document are stored in key-value pairs so, There should be no problem even if the data is received in unordered fashion as long as you are mapping the data correctly in your model.

Fierstore does not set an order for the fields in a document. If you need an order, you will have to apply that in your app code. If you have an array of ordered data to store, consider putting that data in a single list type field instead.

Related