我和HiveFlutter工作,我有这样的结果列表,但我想groupby的日期列表。
结果我想要的是这样的:
1919年12月9日,星期一
啊
啊
啊
啊
我已经在研究,我发现了一些收集包。我尝试使用此脚本按列表分组,但打印的不是我想要的:
var groupData = groupBy(historyList, (obj) => historyList);
print(historyList);
结果
I/flutter (23894): {2019-12-09 01:08:56.328: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:57:22.455: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:57:01.274: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:56:56.992: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
I/flutter (23894): {2019-12-09 00:56:47.549: [Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive', Instance of 'HistoryModelHive']}
你能帮我整理一下名单吗?
如果你需要的话,这是我的模型
WatchBoxBuilder(
box: Hive.box("history_box"),
builder: (ctx, boxx) {
final historyList = boxx.values.toList().cast<HistoryModelHive>();
historyList.sort((first, end) =>
end.dateHistoryCreate.compareTo(first.dateHistoryCreate));
if (historyList.isEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset(
"assets/images/empty2.png",
fit: BoxFit.cover,
height: 250,
),
Text(
'Your History Empty',
textAlign: TextAlign.center,
style: textTheme.display1,
)
],
);
} else {
return ListView.builder(
itemCount: boxx.length,
itemBuilder: (BuildContext context, int i) {
final historyData = historyList[i];
var groupData = groupBy(
historyList, (obj) => historyData.dateHistoryCreate);
print(groupData);
return ListViewHistory(
id: historyData.id,
receiverName: historyData.receiverName,
amountDebt: historyData.amountDebt,
amountLack: historyData.amountLack,
amountSubstract: historyData.amountSubstract,
dateHistoryCreate: historyData.dateHistoryCreate,
imageReceiver: historyData.imageReceiver,
imageSignature: historyData.imageSignature,
nameAction: historyData.nameAction,
);
},
);
}
},
)),
1条答案
按热度按时间v1uwarro1#
你可以使用软件包https://pub.dev/packages/grouped_listview
您可以复制粘贴运行下面的完整代码
代码段
演示
完整代码