如何解决Flutter Getx RxList 产品列表,名称-价格
我想用 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"] );
感谢所有帮助。
解决方法
试试这个:
型号:
x = 8
print('initial x',x,id(x))
while (x != 5):
x = input("Please enter the number 5: ")
print('final_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));
}
如果您使用空安全,此代码有效
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。