如何在flutter中管理离线firebase数据库



我已经使用管理离线firebase数据

Firestore.instance.settings(persistenceEnabled: true);

我从Firebase到SQLite或在flutter中离线存储数据的最佳方式是什么?

但现在它工作得很好,但在火球行动中,它没有进入下一步。我的代码是:

showLoader();
print("2222222222222222");
DocumentReference ref = await _databaseReference
.collection(FirebaseCollection.transcation)
.add(param).catchError((onError){
hideLoader();
print("5555555  $onError");
}).then((onValue){
print("44444444444 $onValue");
});
print("33333333333");
var token = '';
var receiverId = '';
.collection(FirebaseCollection.user)
.document(userId)
.get()
.then((document) async {
UserModel userModel = UserModel.fromsnapshot(document);
print("data");
}

这里我有调试,但只打印2222222222没有其他。当我的设备离线时,我无法隐藏我的加载程序或执行其他任务。

当您在Firestore中使用离线持久性时,不要使用Transactions或await进行响应。

对我来说,当我实现bloc模式时,在存储库的构造函数中,我确实检查了连接状态,并根据这一点进行联机/脱机。

其余的代码保持不变,所以我仍然使用等待等。

bool online = ConnectionStatusSingleton.getInstance().currentStatus;
if(online){
FirebaseDatabase.instance.goOnline();
_databasePropertiesReference.keepSynced(true);
}else{
FirebaseDatabase.instance.goOffline();
}

最新更新