Mwase
Mwase

Reputation: 1042

Convert datetime to other runtimetype in flutter app

I'm trying to convert a DateTime runtimetype value to Expression<DateTime, DateTimeType>. I've been trying to achieve this for almost three days now. I have tried different approaches but non is working.

The reason I want to achieve this is because moor_flutter library in some cases uses and accepts the library's custom runtimetypes on methods and and the parameter values on those methods.

Below is the sample code;

final DateTime dateToday = new DateTime.now(); // convert DateTime to Expression<DateTime, DateTimeType>
var dateWithNewRuntimetype; // assign the converted value to this variable

I thought I fixed this issue by adding as as Expression<DateTime, DateTimeType> to the value of dateWithNewRuntimetype variable value but no this is not the solution either.

The solution will work on the code below

Stream<List> getLoansWithTomorrowDueDate(int dayInFuture) {
    return (select(loans)
          ..where((l) => l.due_date.isBetween(
              dateToday, // it should be Expression<DateTime, DateTimeType> not DateTIme
              futureDate, // it should be Expression<DateTime, DateTimeType> not DateTIme)))
        .watch();
  }

If you want me to provide more info on this I will do so.

Thank you, so much Love.

Upvotes: 0

Views: 247

Answers (1)

Kahou
Kahou

Reputation: 3488

The isBetween is compared withSqlType. You must use isBetweenValues.

/// Defines extension functions to express comparisons in sql
extension ComparableExpr<DT, ST extends ComparableType<DT>>
    on Expression<DT, ST> {

  Expression<bool, BoolType> isBetween(
      Expression<DT, ST> lower, Expression<DT, ST> higher,
      {bool not = false});

  Expression<bool, BoolType> isBetweenValues(DT lower, DT higher,
      {bool not = false});
}

Upvotes: 1

Related Questions