Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 在Flatter中单击按钮时,如何在空动态列表中添加动态项? 处境_List_Flutter - Fatal编程技术网

List 在Flatter中单击按钮时,如何在空动态列表中添加动态项? 处境

List 在Flatter中单击按钮时,如何在空动态列表中添加动态项? 处境,list,flutter,List,Flutter,我有一个动态空列表,类型为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 =

我有一个动态空列表,类型为
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 = [];
List shoeCartList=[];

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

您可以使用
shoeCartList
上的
add
方法将项目[在您的情况下
shoe objects
]
添加到列表的末尾

我以您的代码为例添加了一个演示:

class ListExample extends StatelessWidget {
  List<Shoe> shoeCartList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          height: 55,
          width: double.infinity,
          child: FlatButton(
            onPressed: () {
              // add items here [ use the .add method on the list]
              shoeCartList.add(
                Shoe(
                  b: VALUE OF b,
                  c: VALUE OF c,
                  i: VALUE OF i,
                  iN: VALUE OF iN,
                  q: VALUE OF q,
                ),
              );
            },
            child: Center(
              child: Text(
                'Add Items',
              ),
            ),
          ),
        ),
      ),
    );
  }
}
class ListExample扩展了无状态小部件{
List shoeCartList=[];
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
孩子:大小盒子(
身高:55,
宽度:double.infinity,
孩子:扁平按钮(
已按下:(){
//在此处添加项目[使用列表上的.add方法]
shoeCartList.add(
鞋(
b:b的值,
c:c的值,
i:i的价值,
iN:iN的值,
q:q的值,
),
);
},
儿童:中心(
子:文本(
“添加项目”,
),
),
),
),
),
);
}
}

您可以使用
shoeCartList
上的
add
方法将项目[在您的情况下,
鞋对象
]
添加到列表的末尾

我以您的代码为例添加了一个演示:

class ListExample extends StatelessWidget {
  List<Shoe> shoeCartList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          height: 55,
          width: double.infinity,
          child: FlatButton(
            onPressed: () {
              // add items here [ use the .add method on the list]
              shoeCartList.add(
                Shoe(
                  b: VALUE OF b,
                  c: VALUE OF c,
                  i: VALUE OF i,
                  iN: VALUE OF iN,
                  q: VALUE OF q,
                ),
              );
            },
            child: Center(
              child: Text(
                'Add Items',
              ),
            ),
          ),
        ),
      ),
    );
  }
}
class ListExample扩展了无状态小部件{
List shoeCartList=[];
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
孩子:大小盒子(
身高:55,
宽度:double.infinity,
孩子:扁平按钮(
已按下:(){
//在此处添加项目[使用列表上的.add方法]
shoeCartList.add(
鞋(
b:b的值,
c:c的值,
i:i的价值,
iN:iN的值,
q:q的值,
),
);
},
儿童:中心(
子:文本(
“添加项目”,
),
),
),
),
),
);
}
}

List shoeCartList=[]

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

List shoeCartList=[]

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