【发布时间】:2020-07-23 18:57:02
【问题描述】:
在应用程序中,我有 4 个不同的选项卡,我想显示来自 firestore 的过滤数据。
我有以下标签:
- 全部
- 音乐
- 健身
- 喜剧
第一个选项卡显示未经过滤的所有数据,第二个选项卡显示具有标签“音乐”的数据,依此类推。
我将代码复制了 4 次并更改了 .where 但这个解决方案对我来说似乎不是最好的。
这是我的其中一个标签的代码:
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Center(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Container(
width: MediaQuery.of(context).size.width,
height: 150.0,
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('eventsdata')
.orderBy('dateform')
.where('dateform', isGreaterThanOrEqualTo: _timeminus1)
.where('platform', isEqualTo: 'Comedy')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text(
'Loading...',
style:
TextStyle(fontSize: 15.0, color: Colors.black38),
);
default:
return Padding(
padding: const EdgeInsets.only(bottom: 179.0),
child: new ListView(
有人可以帮我吗?
【问题讨论】:
-
你的问题到底是什么?
-
这段代码中到底有什么不符合您的预期?
-
您好,感谢两位cmets。该代码正在运行,但每次用户切换选项卡时都会加载流。我宁愿在过滤后加载一次流。如何做到这一点?谢谢
标签: flutter google-cloud-firestore cloud