首页 > 解决方案 > 当在颤动中单击按钮时,如何在空的动态列表中添加动态项目?

问题描述

情况

我有一个动态的空列表类型shoe如下

class Shoe {
  String brand;
  int quantity;
  String image;
  Color productColor;
  int indexNumber;
  
  Shoe({String b, int q, String i, Color c, int iN}) {
    brand = b;
    quantity = q;
    image = i;
    productColor = c;
    indexNumber =iN;
  }
}

动态空列表

List<Shoe> shoeCartList = [];

shoeCartList按下按钮时如何在列表中动态添加项目?

标签: listflutter

解决方案


列出 shoeCartList = [];

    onPress(){
          shoeCartList.add(Shoe(add your param));
      }

推荐阅读