【发布时间】:2022-01-23 19:45:09
【问题描述】:
我使用过 Laravel,我们可以在其中定义模型本身内部的关系。那么这在 Dart/Flutter 中是否可行?
我已经构建了这个购物车模型,其中总计应该是动态的。 因此,每当我创建此购物车模型的实例时,一旦我们输入总计和折扣,就会自动计算总计。直到那时默认值 0。
上图代码:
class Cart {
Cart({
this.total = 0,
this.discount = 0,
this.grandTotal, // I want this field dynamic: (grandtotal = total - discount)
});
int total;
int discount;
int? grandTotal;
}
【问题讨论】: