Reputation: 929
I want to get a stream of record which are in the same day of input (like all records with date of Feb 23, 2020).
Stream<List<BloodSugar>> watchBloodSugarsInDate(DateTime date) {
return (select(bloodSugarsEntity)
..where((bp) => bp.date.equals(date)))
.map((bloodSugarsEntity) => convertEntityToModel(bloodSugarsEntity))
.watch();
}
this is my code and it doesn't work because dateTime is combine of date and time. I tried using nested queries for separated comparison of year, month and day but I couldn't make it. Any help would be much appriciated.
Upvotes: 1
Views: 3486
Reputation: 5362
You can get date
from your row
, and just compare with passed searchDate
.
You have to compare year
with year
, month
with month
and day
with day
:
Stream<List<BloodSugar>> watchBloodSugarsInDate(DateTime searchDate) {
return (select(bloodSugarsEntity)
..where(
(row) {
final date = row.date;
return date.year.equals(searchDate.year) &
date.month.equals(searchDate.month) &
date.day.equals(searchDate.day);
},
))
.map((bloodSugarsEntity) => convertEntityToModel(bloodSugarsEntity))
.watch();
}
Upvotes: 2
Reputation: 3488
bool isSameDate(bp) {
final value = bp.date;
return value.year == date.year &&
value.month == date.month &&
value.day == date.day;
}
Upvotes: 1