按下按钮时如何在Flutter上更改文本样式

有人知道按下按钮时如何在Flutter上更改文本样式吗?

例如,我有这样的代码:

class _scanningState extends State<scan> {  

String strText = 'ABCDEFG';

@override

Widget build(BuildContext context) {

return Scaffold(backgroundColor: Colors.blue,

body: new Column(

children: <Widget>[

new Text(strText),

new RaisedButton(

child: new Text('Button'),

onPressed: (){

//Change text style of strText()???

},

)

],

)

);

}

回答:

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;

});

},

)

],

));

}

也许您想更改兄弟文本。概念是相同的。快乐扑

以上是 按下按钮时如何在Flutter上更改文本样式 的全部内容, 来源链接: utcz.com/qa/430933.html

回到顶部