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.
Author by
jerahmeel
Updated on December 08, 2022Comments
-
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.
-
Kato over 5 yearsSee how to ask and creating an mcve.
-
-
jerahmeel over 5 yearsoh, now I know.. Thanks for this! it really helped me..