【发布时间】:2020-11-19 15:10:09
【问题描述】:
我有一个简单的颤振应用程序,我从 Firebase 检索一堆记录。记录中包含一个名为 DATE 的字段,格式为 DateTime。(Date + time + TZ)
但是从我的应用程序中,我怎样才能创建一个页面,我可以在其中过滤仅针对选定 DATE 的记录。
当我使用 .where('time', isGreaterThan : _selectedDate) 时,它可以工作。但它给出了所选日期之后的所有天数。我只想过滤一个选定的日期。
这是我的代码:
Stream<QuerySnapshot> _getCurrentOders() async* {
yield* FirebaseFirestore.instance
.collection('ItemList')
.where('time', isGreaterThan: _selectedDate)
.orderBy('time', descending: false)
.snapshots();
}
我还使用 DateTime 选择器来选择日期。
DateTimeField(
initialValue: DateTime.now(),
onChanged: (val) {
setState(() {
_selectedDate = val;
});
},
format: format,
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(2019),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100));
},
),
感谢您的支持!
【问题讨论】: