【发布时间】:2020-03-20 14:33:06
【问题描述】:
我正在创建一个使用流构建器的应用,从 Firestore 云中提取数据。代码如下:
return Scaffold(
backgroundColor: Colors.black,
appBar: appBar,
drawer: Sidebar(),
body: Center(
child: StreamBuilder(
stream: stream,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text(
"Loading...",
style: TextStyle(
color: Colors.white,
),
);
} else {
return GridView.builder(
itemCount: snapshot.data.documents.length,
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: globals.gridCountValue != null ? globals.gridCountValue : 2,
),
itemBuilder: (context, index) {
return _buildList(context, snapshot.data.documents[index]);
},
);
}
},
),
),
floatingActionButton: FloatingActionButton(
// onPressed: () => shuffleAlbums(),
onPressed: () {},
child: Icon(Icons.shuffle),
elevation: 2,
backgroundColor: Colors.black,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
_buildList:
Widget _buildList(BuildContext context, DocumentSnapshot document) {
if (document.data != null) {
return new AlbumTile(data: document.data);
}
}
当我使用硬编码的专辑列表时,我能够打乱列表的顺序,但现在我使用的是流构建器,我不知道如何达到这个结果。我基本上想按一个按钮以随机顺序重新排序列表。
感谢您的阅读!
【问题讨论】:
标签: android flutter dart google-cloud-firestore spotify-app