我想用 Getx 创建一个篮子,我将值定义为名称和价格,我想将基本产品添加到购物篮中。如何将字符串作为名称或双倍作为产品的价格添加到 PriceModel2 -RxList 中?
产品型号-
class PriceModel2 {
String name;
double price;
PriceModel2(String name, double price) {
this.name = name;
this.price = price;
}
}
添加功能
RxList<PriceModel2> basket = [].obs;
urunEkle(String isim) {
basket.add(isim);
basket.add(isim<basket>[name]);
}
界面
ElevatedButton(
onPressed: () {
controller.urunEkle(
material["name"] );
感谢所有帮助。
答案 0 :(得分:0)
试试这个:
型号:
x = 8
print('initial x', x, id(x))
while (x != 5):
x = input("Please enter the number 5: ")
print('final_x', x, id(x))
功能:
class PriceModel2 {
final String name;
final double price;
PriceModel2( {required this.name,required this.price,});
}
界面:
List<PriceModel2> basket = <PriceModel2>[].obs;
void urunEkle(String isim, double fiyat) {
basket.add(PriceModel2(name: isim, price: fiyat));
}
如果您使用空安全,此代码有效