I am newbie, and I am using package grouped_list to group the list with data from the SQLite database, grouped_list works fine with an existing list just like in its example, but when I replace it equals list with data retrieved from SQLite database then it doesn't work and I get error:
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")
Below is my code. If you need more information please let me know, please help, thank you!
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();
},
)
This is how I declare the list:
List drinkList = List<DrinkDatabase>();
And class 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}, ';
}
}
What I did and it worked for me
The way to declare the list
Then replace the line
with
To build the list from the database query result list
In DrinkDatabaseHelper
If you have more questions let me know