我无法增加购物车数量值

  • 本文关键字:购物车 增加 flutter
  • 更新时间 :
  • 英文 :


我想增加购物车的数量,但是我不能。我显示错误" ;======== 例外被手势 ===============================================================在处理手势时抛出以下UnsupportedError:不支持的操作:索引集"点击"+"的象征。这是布局的图像这是我的代码:

Expanded(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: ListView.builder(
itemCount: value.hotelcart.length,
padding: EdgeInsets.all(12),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(12.0),
// child:
// Visibility(
// visible: value.hotelcart[index][4] >= 0,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8)),
child: ListTile(
leading: Image.asset(
value.hotelcart[index][2],
height: 100,
),
title: Text(
value.hotelcart[index][0],
style: const TextStyle(fontSize: 18),
),
subtitle: Text(
'Rs ' + value.hotelcart[index][1],
style: const TextStyle(fontSize: 12),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(Icons.add),


**onPressed: (){
setState(()
{
value.hotelcart[index][4]++;

});
}, 
),**
// Text("${value.hotelcart[index][4]}"),
Text(value.hotelcart[index][4].toString(),),
IconButton(
icon: Icon(Icons.remove),
onPressed: () =>
Provider.of<hotelItem>(context, listen: false)
.removeItemFromCart(index),
),
],
),

),
),
);
},
),
),
),`

我想增加购物车数量,但它只显示了列表中给出的1个。显示cat处理错误

如果您的Expanded部件已经被Consumer包装,则不需要调用setState只需在提供程序中定义函数来添加或删除并调用notifyListeners(),例如

void add(int index) {
hotelcart[index][4]++;
notifyListeners();
}

使用和

IconButton(
icon: Icon(Icons.add),
onPressed: () => value.add(index),
)

相关内容

最新更新