I have this Text
I want when I clicked on add Icon to refresh 30 to 31
this is my code :
Row(
children: <Widget>[
Expanded(
child: Container(
height: 30.0,
width: 30.0,
child: Image.asset('assets/images/trash_can.png'),
),
),
Expanded(
child: Center(
child: Text(
mealsNum.toString(),
style: TextStyle(
fontSize: 20.0
),
),
),
),
Expanded(
child: GestureDetector(
onTap: (){
mealsNum++;
print(mealsNum);
},
child: Icon(
Icons.add,
color: Color(0xffFFD243),
),
),
),
],
),
How can I do this?
use a set state to update
onTap: (){
setState((){
mealsNum++;
});
print(mealsNum);,
You need to add setState in onTap
Row(
children: <Widget>[
Expanded(
child: Container(
height: 30.0,
width: 30.0,
child: Image.asset('assets/images/trash_can.png'),
),
),
Expanded(
child: Center(
child: Text(
mealsNum.toString(),
style: TextStyle(
fontSize: 20.0
),
),
),
),
Expanded(
child: GestureDetector(
onTap: (){
setState(() {
mealsNum++;
});
print(mealsNum);
},
child: Icon(
Icons.add,
color: Color(0xffFFD243),
),
),
),
],
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With