我是新手,我正在使用包 grouped_list 将列表与 SQLite 数据库中的数据分组,grouped_list 与现有列表一起工作,就像在它的示例中一样,但是当我用从 SQLite 数据库检索的数据替换它等于列表时,它不会'不工作,我得到错误:
The following NoSuchMethodError was thrown building GroupedListView<dynamic, String>(dirty, state: _GroupedListViewState<dynamic, String>#c2ba2):
Class 'DrinkDatabase' has no instance method '[]'.
Receiver: Instance of 'DrinkDatabase'
Tried calling: []("drinkGroup")
下面是我的代码。如果您需要更多信息,请告诉我,请帮助,谢谢!
GroupedListView<dynamic, String>(
shrinkWrap: true,
elements: homeController.drinkList,
groupBy: (element) => element['drinkGroup'],
groupComparator: (value1, value2) => value2.compareTo(value1),
itemComparator: (item1, item2) =>
item1['drinkDateTime'].compareTo(item2['drinkDateTime']),
order: GroupedListOrder.DESC,
useStickyGroupSeparators: true,
groupSeparatorBuilder: (String value) =>
Container(),
itemBuilder: (c, element) {
return Container();
},
)
这就是我声明列表的方式:
List drinkList = List<DrinkDatabase>();
和类 DrinkDatabase:
class DrinkDatabase {
int drinkId;
int drinkVolume;
String drinkGroup;
String drinkCategory;
String drinkDateTime;
DrinkDatabase({
this.drinkId,
this.drinkVolume,
this.drinkGroup,
this.drinkCategory,
this.drinkDateTime,
});
Map<String, dynamic> toMap() {
return {
"drinkId": drinkId,
"drinkVolume": drinkVolume,
"drinkGroup": drinkGroup,
"drinkCategory": drinkCategory,
"drinkDateTime": drinkDateTime,
};
}
@override
String toString() {
return 'drinkTable('
'"drinkId": ${this.drinkId}, '
'"drinkVolume": ${this.drinkVolume}, '
'"drinkGroup": ${this.drinkGroup}, '
'"drinkCategory": ${this.drinkCategory}, '
'"drinkDateTime": ${this.drinkDateTime}, ';
}
}