Why is my flutter app saves twice on firestore while my device is offline?

466

Firestore doesn't support transactions neither await keyword for offline mode, just remove the runTransaction and await.

  Future<void> saveHouseHolder() async {
      CollectionReference reference = Firestore.instance
            .collection('municipality')
            .document(global.mundocid)
            .collection('Barangay')
            .document(global.brgydocid)
            .collection('HouseHolderList');
         reference.add({
          'Name': name,
          'Gender': gender,
          'Age': age,
          'Spouse': spouse,
          'FullAddress': fullAdd,
          // 'Location':new GeoPoint(latitude, longitude),
          'ContactNumber': contactNo,
          'Origin': origin,
          'Language': language
        });

      Navigator.of(context).push(MaterialPageRoute(builder: (context) => HouseHolder()));

        }

After your connection is restored, it will sync automatically.

Share:
466
jerahmeel
Author by

jerahmeel

Updated on December 08, 2022

Comments

  • jerahmeel
    jerahmeel over 1 year

    When my device is offline and tried to insert into firestore, it executes twice.

    this my code in adding document to firestore.

  • jerahmeel
    jerahmeel over 5 years
    oh, now I know.. Thanks for this! it really helped me..