I'm new to dart/flutter. There is a list generated using List.generate
method which returns a dictionary. Now, I want to sort the list by 'day' key values as 'Sun, Mon, ...., Sat' as shown in the following piece of code.
final filteredTransactions = List.generate(7, (index) {
final weekDay = DateTime.now().subtract(Duration(days: index));
var totalSum = 0.0;
for (var i = 0; i < recentTransactions.length; i++) {
if (recentTransactions[i].date.day == weekDay.day &&
recentTransactions[i].date.month == weekDay.month &&
recentTransactions[i].date.year == weekDay.year) {
totalSum += recentTransactions[i].amount;
}
}
return {'day': DateFormat.E().format(weekDay), 'amount': totalSum};
})
最近交易是一个包含对象日期和金额数据的列表。如何按“天”对filteredTransactions进行排序?谢谢。
You can give
List.sort()
a custom sort method like this: