【发布时间】:2021-02-06 14:25:16
【问题描述】:
我正在尝试用我的 Firebase 存储中的图像填充 GridView.builder。我想通过查询从我的 Firestore 数据库中获取 url。我找不到任何好的教程,并尝试自己构建该功能,但没有奏效。在 FutureBuilder 中,我打印了应具有数据变量的快照变量,但它没有。
Container(
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
height: deviceHeight * 0.35,
width: deviceWith,
color: Colors.white,
child: FutureBuilder(
future: getImages(),
builder: (context, AsyncSnapshot<dynamic>snapshot) {
print(snapshot);
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.docs.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
contentPadding: EdgeInsets.all(8.0),
title: Text(snapshot.data.docs[index].data()["name"]),
leading: Image.network(
snapshot.data.docs[index].data()["url"],
fit: BoxFit.fill),
);
});
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
}
return CircularProgressIndicator();
},
),
),
Future getImages() {
var data;
page.where("userID",isEqualTo: FirebaseAuth.instance.currentUser.uid).snapshots().listen((data){
return data.docs;
});
return data;
}
我只更改了教程中的 Future 函数,没有更改 FutureBuilder 变量,但我知道我必须更改它们。
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore