How to change a text style on Flutter when button pressed

后端 未结 2 683
遥遥无期
遥遥无期 2021-01-11 23:21

Is anyone know how to change a text style on Flutter when the button pressed?

As example, i have a code like this :

class _scanningState extends Stat         


        
2条回答
  •  情话喂你
    2021-01-11 23:31

    class _scanningState extends State {
      bool pressed = true;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            backgroundColor: Colors.blue,
            body: new Column(
              children: [
                new Text(strText,
                        style: pressed
                        ? TextStyle(color: Colors.black)
                        : TextStyle(color:Colors.green),
                ),
                new RaisedButton(
                  child: new Text(
                    'Change color'),
                  onPressed: () {
                    setState(() {
                      pressed = !pressed;
                    });
                  },
                )
              ],
            ));
      }
    

    Maybe you want to change the sibling text. The concept is the same. Happy Flutter

提交回复
热议问题