gpt4 book ai didi

flutter - Flutter-如何制作一张卡片列表,列出每年每个月的元素?

转载 作者:行者123 更新时间:2023-12-03 04:38:22 24 4
gpt4 key购买 nike

费用运输工具

 class Transactions {
final String id;

final double amount;
final String date;


const Transactions({
@required this.id,
@required this.amount,
@required this.date,

});

Transactions.fromMap(
Map map,
) : this.id = map['id'],
this.amount = map['amount'],
this.date = map['date'],


Map toMap() {
return {
// 'color': this.color,
'id': this.id,
'amount': this.amount,
'date': this.date,

};
}
}
我正在尝试制作一张卡片 list ,以告知用户在当年的几个月中所花费的费用,如下所示:
enter image description here
我已经试过了
    return List.generate(2, (index) {

final weekDay = DateTime.now().subtract(
Duration(days: index),
);
var totalSum = 0.0;

for (var i = 0; i < widget.transactions.length; i++) {
if (DateTime.parse(widget.transactions[i].date).year == weekDay.year &&
DateTime.parse(widget.transactions[i].date).month ==
weekDay.month) {
totalSum += widget.transactions[i].amount;
}
}

// for (var i = 0; i < widget.transactions.length; i++) {
// totalSum = widget.transactions[index].amount + totalSum;
// }

return {
'day': DateFormat.E().format(weekDay).substring(0, 1),
'amount': totalSum,
};
}).reversed.toList();
}

double get totalSpending {
return groupedTransactionValues.fold(0.0, (sum, item) {
return sum + item['amount'];
});
}
但是它没有按照我想要的去做。
................................................... ................................................... .....

最佳答案

嗯,最简单的方法之一就是将数据整理到一个列表中,其中每个元素每个月都有相关的详细信息(即金额)
例:

class Month{
int month; //between 1 and 12
double amount;
}
因此,您只需要在构建函数中实现列表,如下所示:
build(context){
return(
//...
child: List.builder(
itemCount: yourlist.length
itemBuilder: (context, index){
return YourTileWidget(month: yourlist[index].month, amount: yourlist[index].amount)
}
),
//...
);
}
希望这是您想要实现的目标!

关于flutter - Flutter-如何制作一张卡片列表,列出每年每个月的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63699014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com