我正在使用sqlite数据库使用颤动包来实现这个目的。我一直在尝试将limit
方法应用于某个查询,但它不起作用。在limit
方法中,我解析int _limit
参数值以及可选的offset: int _offset
参数值。
我没有得到任何错误,我也不知道为什么这不起作用。请看下面的代码。
Stream<List<PersonWithProducts>> watchAllPersons(int _limit, int _offset) {
return (select(persons)
..orderBy(
[
(t) =>
OrderingTerm(expression: t.created, mode: OrderingMode.desc),
(t) => OrderingTerm(expression: t.name),
],
)..limit(_limit, offset: _offset))
.join(
[
leftOuterJoin(products, products.guest_person_id.equalsExp(persons.id)),
],
)
.watch()
.map((rows) => rows.map(
(row) {
return PersonWithProuducts(
person: row.readTable(persons),
product: row.readTable(products),
);
},
).toList());
}
备注表中的20
记录更多。当我调用函数(首先,从数据库表中获取数据而不是指定的限制)时,就好像忽略了limit()
方法。
参见下面的代码,这里是我调用上述函数的地方
int limit = 5;
int offset = 0;
return StreamBuilder(
stream: personDao.watchAllPersons(limit, offset),
builder: (context, AsyncSnapshot<List<PersonWithProducts>> snapshot) {
final persons = snapshot.data ?? List();
// print('snapshot data: ${snapshot.data}');
if (snapshot.hasData) {
return ListView.builder(
itemCount: persons.length,
itemBuilder: (_, index) {
final personInfo = persons[index];
return _buildListItem(
personInfo, personDao);
},
);
} else {
return Center(
child: AwesomeLoader(
loaderType: AwesomeLoader.AwesomeLoader4,
color: Colors.blue,
),
);
}
},
);
我想要的是watchAllPersons
函数来根据指定的limit
获取数据。我想让limit
方法发挥作用。谢谢,真爱你。
发布于 2020-03-04 08:46:43
为什么你要给“限制”变量加上下划线--这意味着你把变量变成了私有变量。
发布于 2021-02-08 11:38:57
虽然已经有一段时间了,但我忘了提供解决方案,这是我发布的问题这里包中的一个错误。
https://stackoverflow.com/questions/60503062
复制相似问题