【问题标题】:Flutter Getx RxList Product List, Name-PriceFlutter Getx RxList 产品列表,名称-价格
【发布时间】:2021-10-01 09:22:27
【问题描述】:

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

感谢所有帮助。

【问题讨论】:

    标签: android list flutter dart flutter-getx


    【解决方案1】:

    试试这个:

    型号:

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

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

    【讨论】:

    • 嗨,它给出了这个问题。 prnt.sc/1fno776,我还在 String 和 Double 之前添加了 final Tag,然后,prnt.sc/1fnoryx
    • 它的工作不需要! ,我很高兴你先生,Herrlich!prnt.sc/1fnsor7
    • 太棒了!乐于助人
    猜你喜欢
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2021-01-02
    • 2019-08-06
    • 2015-02-25
    • 2021-04-23
    • 1970-01-01
    相关资源
    最近更新 更多