Я делаю приложение во флаттере, которое содержит продукты, мне нужно уметь увеличивать и получать ключ увеличенного продукта для хранения, в настоящее время они увеличивают все.
Я оставляю изображение и мой код, спасибо за помощь
Когда нажимаете на иконку добавления, добавьте два счетчика продукта
Widget _buildSearchResults() {
return new ListView.builder(
itemCount: _productSearchResult.length,
itemBuilder: (context, i) {
return new Card(
child: Column(
children: <Widget>[
ExpansionTile(
leading: new CircleAvatar(
backgroundImage: new NetworkImage(_productSearchResult[i].image_url),
),
title: new Text(
'${_productSearchResult[i].name} \nPrecio: Q${_productSearchResult[i].price} / Medida: ${_productSearchResult[i].unit } ',
),
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new Container(
child: new IconButton(
icon: new Icon(Icons.remove),
highlightColor: Colors.green,
onPressed: (){
_removeProduct();
},
),
),
new Container(
child: new Text('$_counter',
style: Theme.of(context).textTheme.display1,),
),
new Container(
child: new IconButton(
icon: new Icon(Icons.add),
highlightColor: Colors.green,
onPressed: (){
_addProduct();
},
),
),
new Container(
padding: new EdgeInsets.all(10.0),
width: 100.0,
child: new RaisedButton(
padding: const EdgeInsets.all(8.0),
textColor: Colors.white,
color: Colors.green,
onPressed: _addNumbers,
child: new Text("Agregar"),
),
),
]
),
]
),
],
)
);
},
);
}
_removeProduct() {
setState(() {
if (_counter > 0) {
_counter--;
}
});
}
_addProduct() {
setState(() {
_counter++;
});
}