Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh text in flutter

I have this Text

enter image description here

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?

like image 537
Laila Mattar Avatar asked Dec 14 '22 07:12

Laila Mattar


2 Answers

use a set state to update

 onTap: (){
    setState((){                                    
mealsNum++;
});

  print(mealsNum);,
like image 86
griffins Avatar answered Jan 02 '23 15:01

griffins


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),
        ),
      ),
    ),
  ],
),
like image 44
lsaudon Avatar answered Jan 02 '23 14:01

lsaudon