【问题标题】:Why is my flutter app saves twice on firestore while my device is offline? [closed]为什么我的设备离线时,我的 Flutter 应用程序会在 Firestore 上保存两次? [关闭]
【发布时间】:2023-03-11 12:20:01
【问题描述】:

当我的设备离线并尝试插入 Firestore 时,它​​会执行两次。

这是我在adding document 中的代码到firestore。

【问题讨论】:

标签: firebase dart flutter google-cloud-firestore


【解决方案1】:

Firestore 不支持事务,也不支持离线模式的await 关键字,只需删除 runTransaction 并等待即可。

  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()));

        }

连接恢复后,会自动同步。

【讨论】:

  • 哦,现在我知道了……谢谢!它真的帮助了我..
猜你喜欢
  • 2018-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-06
  • 2019-04-13
  • 2011-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多