Flutter SQLite获取两个日期之间的值,一个是动态的(Flutter Moor)



我正在构建一个金融应用程序,创建了一个名为wallets的表,wallets表有一列名为startDate。使用SQLite 的(flatter_mor(包

现在我只需要检索最新创建的钱包,并且只有在使用上面字段startDate的值创建钱包后30天内,这意味着在新的月份我无法获得

我的代码:

Stream<Wallet> watchLatestCreatedWallet() {
final Stream<Wallet> wallet = (
select(wallets)
..orderBy([
(wallet) => OrderingTerm(
expression: wallet.startDate,
mode: OrderingMode.desc
) 
])
// somthing wrong I did, obviously always will return true
// ..where((tbl) => tbl.startDate.isBetween(tbl.startDate, tbl.startDate + Duration(days: 30) ) )
..limit(1)
)
.watchSingle();
return wallet;
}

修复了此问题

Stream<Wallet> watchLatestCreatedWallet() {
final endRange = DateTime.now();
final startRange = endRange.subtract(Duration(days: 30));
final Stream<Wallet> wallet = (
select(wallets)
..orderBy([
(wallet) => OrderingTerm(
expression: wallet.startDate,
mode: OrderingMode.desc
) 
])
..where((tbl) => tbl.startDate.isBetween(startRange, endRange ) )
..limit(1)
)
.watchSingle();
return wallet;
}

最新更新