How to change a text style on Flutter when button pressed

后端 未结 2 704
遥遥无期
遥遥无期 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:29

    I recommend you to read about Stateful Widgets https://flutter.io/tutorials/interactive/#stateful-stateless

        class _scanningState extends State {
          bool pressed = false;
          String strText = 'ABCDEFG';
    
          @override
          Widget build(BuildContext context) {
            return Scaffold(
                backgroundColor: Colors.blue,
                body: new Column(
                  children: [
                    new Text(strText),
                    new RaisedButton(
                      child: new Text(
                        'Button',
                        style: pressed
                            ? TextStyle(fontSize: 30.0)
                            : TextStyle(fontSize: 10.0),
                      ),
                      onPressed: () {
                        //Change text style of strText()???
                        setState(() {
                          pressed = !pressed;
                        });
                      },
                    )
                  ],
                ));
          }
    

提交回复
热议问题