class _ChildDataState extends State<ChildData> {
int totalPrice = 0;
List totalHarga = List();
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: widget.items.length,
itemBuilder: (context, i) {
int price = int.parse(widget.items[i].price.split('.').first);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
widget.items[i].image ?? '',
),
),
),
),
SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.items[i].name,
style: blackTextFont.copyWith(
fontWeight: FontWeight.bold),
),
SizedBox(height: 5),
Text(
"Rp. ${widget.items[i].price.split('.').first} / ${widget.items[i].unit}",
style: blackNumberFont),
SizedBox(height: 8),
Text(widget.items[i].description),
SizedBox(height: 8),
SizedBox(height: 8),
widget.items[i].counter != 0
? Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: mainColor,
),
width: 30,
height: 30,
child: IconButton(
icon: Icon(
Icons.remove,
size: 15,
color: Colors.white,
),
onPressed: () {
setState(
() {
widget.items[i].counter--;
totalPrice -= price;
widget.onTotalChange(totalPrice.toString());
},
);
},
),
),
Text(widget.items[i].counter.toString()),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: mainColor,
),
width: 30,
height: 30,
child: IconButton(
icon: Icon(
Icons.add,
size: 15,
color: Colors.white,
),
onPressed: () {
setState(() {
widget.items[i].counter++;
totalPrice += price;
widget.onTotalChange(totalPrice.toString());
});
},
),
),
],
)
: Center(
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4),
color: mainColor,
),
width: double.infinity,
height: 30,
child: Center(
child: Text("ADD",
style: whiteTextFont),
)),
onTap: () {
setState(() {
widget.items[i].counter++;
totalPrice += price;
widget.onTotalChange(totalPrice.toString());
});
},
),
),
],
),
)
],
),
],
);
},
),
),
],
);
I had a product data and the product child data then, when I want to show the product data and the product child data I have to create a new widget and place it inside product data `ListView.builder`. I have solved count the product child totalprice and now I want to count the entire totalPrice from the different widget.