我从firestore数据库中获取了一些数据,利用这些数据,我创建了一个ListView来显示我的数据。
我想在列表的底部追加3个与生成的静态项目不同的静态项目。
我用于建立列表的代码是:
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('users').document(userAdminId)
.collection('events')
.where('operatore', isEqualTo: _user)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
switch (snapshot.data) {
case null:
return Container();
default:
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
final item = snapshot.data.documents[index];
final itemID =
snapshot.data.documents[index].documentID;
final list =
snapshot.data.documents;
return Card(
...
},
);
}
},
),
现在它会生成2张卡片,因为我从数据库中获得了2个事件
我想做的是在此列表的底部再添加3张卡片,
越来越像这样的东西:
Card(
child: Row(
children: <Widget>[
Icon(
Icons.camera_alt
),
Text('Camera')
],
),
)
Card(
child: Row(
children: <Widget>[
Icon(
Icons.folder
),
Text('Media')
],
),
)
Card(
child: Row(
children: <Widget>[
Icon(
Icons.users
),
Text('Friends')
],
),
)
无论它从数据库生成多少个项目,我都希望在底部添加这3张卡片
示例:
如果我获得3个事件,我的名单应该是:
[event1]
[event2]
[event3]
[camera]
[media]
[friends]
如果我只收到一个事件:
[event1]
[camera]
[media]
[friends]
答案 0 :(得分:0)
我通过SliverList
小部件解决了这个问题
此代码为示例:
Widget buildGridFilesToExport() {
return new StreamBuilder(
stream: Firestore.instance
.collection('users')
.document(dataUserGlobal.userAdminId)
.collection('events')
.document(dataUserGlobal.eventId)
.snapshots(),
builder: (context, snapshot) {
print(snapshot);
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return dataUserGlobal.showLoading(dataUserGlobal.purple);
default:
List videosList = snapshot.data['thumbnailsUrl'];
return videosList != null ?
CustomScrollView(
slivers: [
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
childAspectRatio: 1,
),
delegate: SliverChildBuilderDelegate((context, index) {
return Container(
padding: EdgeInsets.all(5.0),
child: Column(
children: <Widget>[
Expanded(
flex: 7,
child: Stack(
children: <Widget>[
Container(
margin:
EdgeInsets.only(bottom: 2.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(5.0)),
image: DecorationImage(
image: NetworkImage(snapshot
.data['thumbnailsUrl']
[index]),
fit: BoxFit.cover,
),
),
),
],
)),
],
));
}, childCount: snapshot.data['thumbnailsUrl'].length),
),
SliverList(
delegate: SliverChildListDelegate([
closeEvent(),
]),
)
],
)
:
Center(
child: Container(
width: 250,
child: Text(
'Ancora nessun video!\nCarica i video dalla sezione media, oppure vai nella sezione amici e seleziona i video da spostare qui!',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'acumin-pro',
fontSize: 22,
),
),
)
);
}
},
);
}