首页 > 解决方案 > 如何编写在 Flutter/moor 中返回 Future 的 cotomselect 查询

问题描述

我正在通过颤振/摩尔开发应用程序。但我不知道如何编写返回 Future<List> 类对象的自定义查询。

我可以编写返回 Stream 类对象的查询。但这还不够。现在有没有人如何将其更改为返回 Future 类的方法。

我写的查询如下

db.dart

Stream<List<QuestionHeader>> selectQuestionHeaderByKey(int businessYear,int period, int questionNo) {
    return
      customSelect(
        'SELECT *'
            +'From question_Headers '
            +'WHERE business_Year = ? '
            +'AND period = ? '
            +'AND question_No = ?;',
        variables: [Variable.withInt(businessYear),Variable.withInt(period),Variable.withInt(questionNo)],
        readsFrom: {questionHeaders},
      ).watch().map((rows) {
        return rows
            .map((row) => QuestionHeader(
            businessYear:row.readInt('businessYear')
            ,period:row.readInt('period')
            ,questionNo:row.readInt('questionNo')
            ,subjectId:row.readInt('subjectId')
            ,compulsoryType:row.readInt('compulsoryType')
            ,answerType:row.readInt('answerType')
            ,questionText:row.readString('questionText')
            ,numberAnswer:row.readInt('numberAnswer')
            ,correctType1:row.readInt('correctType1')
            ,correctType2:row.readInt('correctType2')
            ,correctType3:row.readInt('correctType3')
            ,favorite:row.readBool('favorite')
        )).toList();
      });
  }

这可行,但我需要 Future<List> 类返回。

标签: sqliteflutter

解决方案


推荐阅读