【问题标题】:Table_Calendar how to filter only the day of the monthTable_Calendar 如何仅过滤月份中的某一天
【发布时间】:2020-09-30 15:22:15
【问题描述】:

我目前正在填写一个漂亮的表日历 (https://pub.dev/packages/table_calendar)

为了获取我目前正在执行的数据:

            Firestore.instance
              .collection('nurseries')
              .document(widget._favoriteNurseryId)
              .collection('events')
              .orderBy('eventDateStart')
              .snapshots(),

我需要找到一种解决方案,仅针对屏幕上显示的月份过滤数据。现在我获取数据库上的所有事件。它花费了我太多的 firestore 读取。

【问题讨论】:

  • 嘿,您能否在保存事件的过程中包含 Firestore 结构?

标签: flutter


【解决方案1】:

更新: 我最初误解了这个问题。要获取日历上的开始和结束日期,您可以在 OnSelectedDaySelected 上收听并根据日历格式确定开始和结束日期。

或者

收听OnCalendarCreatedOnVisibleDaysChaned 事件回调以获取日历上的开始和结束日期。

参考:https://pub.dev/documentation/table_calendar/latest/table_calendar/table_calendar-library.html

听起来您需要查询数据而不是获取所有内容。以下查询应该可以工作:

Firestore.instance
  .collection('nurseries')
  .document(widget._favoriteNurseryId)
  .collection('events')
  .orderBy('eventDateStart')
  .startAt('startDate')   // startAfter
  .endAt('endDate')     // endBefore
  .snapshots()

【讨论】:

  • 啊,我明白了,但是您可以收听onDaySelected 回调,并且基于日历格式,只需使用月/日/2 周的开始和结束进行查询。
【解决方案2】:

我不能很好地理解你的问题,但是,我想你搜索一下

FieldValue.serverTimestamp()

试试看

【讨论】:

  • 每次人们打开日历时,所有的事件都会被加载并花费我大量的 firestore 读取。我只想获取当前显示的月份。当用户进入下个月时,它将获取下个月的数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多