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

Flutter SQLite get value between 2 dates, one is dynamic ( flutter Moor )

我正在构建一个财务应用程序,创建了一个名为钱包的 table,钱包 table 有一个名为 startDate 的列。对 SQLite

使用 ( flutter_moor ) 包

现在我只需要检索最新创建的钱包,并且只有在使用上述字段 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;
}