If you want to change a text style on Flutter when button pressed? Use the below example code to change a text style on Flutter when button pressed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | class _scanningState extends State<scanning> { bool pressed = true; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.blue, body: new Column( children: <Widget>[ new Text(strText, style: pressed ? TextStyle(color: Colors.black) : TextStyle(color:Colors.green), ), new RaisedButton( child: new Text( 'Change color'), onPressed: () { setState(() { pressed = !pressed; }); }, ) ], )); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.