【发布时间】:2021-01-07 12:30:08
【问题描述】:
有人可以向我解释如何使用位于 FutureBuilder 内部的 ListView.Builder 中的 itemCount。
目前我的 FirebaseCloud 商店只有一个 Document ,而我的应用正在返回一个无限的文档列表,
我尝试使用itemCount: snapshot.data.documents.length,
但是,得到错误:Class 'DocumentSnapshot' has no instance getter 'documents'. Receiver: Instance of 'DocumentSnapshot' Tried calling: documents
编辑如果有多个与 UID 相关的文档,它应该只显示该文档一次并且一种类型
这是我的代码
final tabs = [
Center(
child: (Scaffold(
body: FutureBuilder(
future: FirebaseFirestore.instance
.collection('users')
.doc(uid)
.get(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.data == null)
return CircularProgressIndicator();
DocumentSnapshot manuais = snapshot.data;
if (snapshot.hasData) {
print('okkk');
print(manuais.data()['nome']);
} else {
print('nopeeeee');
}
return Container(
padding: EdgeInsets.all(16),
child: ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot manuais = snapshot.data;
return Card(
color: Colors.grey[250],
child: Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
new Image.asset(
'Images/pdflogo.png',
width: 32,
),
Center(
child: Text(
(manuais.data()['nome'].toString()),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 16),
),
),
ButtonBar(
children: <Widget>[
FlatButton(
child: const Text(
'Compartilhar / Download'),
onPressed: () async {
var request = await HttpClient()
.getUrl(Uri.parse(manuais
.data()['documento']));
var response =
await request.close();
Uint8List bytes =
await consolidateHttpClientResponseBytes(
response);
await Share.file(
'ESYS AMLOG',
'Manual.pdf',
bytes,
'image/jpg');
}),
],
),
],
),
),
);
}),
);
})))),
````
【问题讨论】:
标签: database firebase flutter dart google-cloud-firestore