无法将参数类型'int'分配给参数类型'Expression <int,IntType>'

时间:2020-02-24 14:34:09

标签: sqlite datetime flutter dart flutter-moor

我正在使用moor_flutter软件包与Flutter应用上的sqlite数据库进行交互。我试图将明天解析为一个月中的天数。例如,今天的日期是24,因此我要在moor_flutter的25方法中将isSmallerOrEqual()解析为明天。目的是像runtimetype **Expression<int, IntType>**中那样解析25,但我将其解析为runtimetype **int**,这是因为我不知道如何将int转换为Expression<int, IntType>。我尝试了一些不同的方法,但没有一个成功。

下面是我正在执行的功能。

Future NearDueDate() {
    // final DateTime currentDate = new DateTime.now();
    var dayToday = currentDate.day;
    var tommorow = int.parse(dayToday.toString()) + 1;
    return (select(the_records)
          ..where((t_r) => t_r.due_date.day.isSmallerOrEqual(tommorow)))
        .get();
  }

注意,这里的问题是如何将int转换为Expression<int, IntType>,这样我就不会在t_r.due_date.day.isSmallerOrEqual(tommorow)上遇到任何错误?

谢谢,发布了爱。

1 个答案:

答案 0 :(得分:0)

对不起,我无法评论这个答案。

如果Expression是某种模型。您将必须通过创建Expression的实例来对其进行转换。

以这个为例:

我们有一个模型,User

class User {

    int _id;
    String _name;

    User(this._name);

    User.withId(this._id, this._name );

    int get id => _id;

    String get name => _name;

    set name(String newName) {
        if (newName.length <= 255) {
            this._name = newName;
        }
    }

    // Convert a User object into a Map object
    Map<String, dynamic> toMap() {

        var map = Map<String, dynamic>();
        if (id != null) {
            map['id'] = _id;
        }
        map['name'] = _name;

        return map;
    }

    // Extract a User object from a Map object
    User.fromMapObject(Map<String, dynamic> map) {
        this._id = map['id'];
        this._name = map['name'];
    }
}

这是这里的重点

要创建User类型,我们将执行以下操作

user = User('John');

现在user.name的类型为User<String>

通常,'John'只是一个字符串。现在,它是User类的一部分。是User<String>