我正在使用一些 Sqflite 和 firestore 数据库构建一个 flutter 应用程序 现在我遇到了一个问题,每当我运行该应用程序时。我第一次将 snapshot.hasdata 设置为 true,然后立即将 snapshot.hasdata 设置为 false。我在此处附上控制台和代码的屏幕截图
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('ADs CommonGroup')
.orderBy("id", descending: true)
.orderBy("id", descending: true)
.where('id', isEqualTo: databaseLogin[0]["number"])
.snapshots(),
builder: (
BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot,
) {
print('snapshot does not have data ${snapshot.hasData}');
print(databaseLogin[0]["number"]);
现在控制台打印出这个
I/flutter (16812): snapshot does not have data false
I/flutter (16812): +923335885631
I/flutter (16812): snapshot does not have data true
I/flutter (16812): +923335885631
I/flutter (16812): snapshot does not have data false
I/flutter (16812): +923335885631
我认为 snapshot.has 数据应该返回 true,因为应用程序像以前一样工作
使用
AsyncSnapshot
时的第一步是处理错误。以简单的形式:
builder: (
BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot,
) {
if (snapshot.hasError) {
print(snapshot.error);
return Text("ERROR: ${snapshot.error}");
}
print('snapshot does not have data ${snapshot.hasData}');
print(databaseLogin[0]["number"]);
...
这可能会告诉您问题的原因。