Flutter Getx RxList 产品列表,名称-价格

饼干

我想用 Getx 创建一个篮子,我将一个值定义为名称和价格,我想将基本产品添加到购物篮中。如何将字符串作为名称或双倍作为价格从 Product 添加到 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"] );

感谢所有帮助。

美索达22

尝试这个:

模型:

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));
}

用户界面:

 ElevatedButton(
    onPressed: () {
      controller.urunEkle("isim", 9.00);
    },

如果您使用空安全,则此代码有效

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章