有谁知道在 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
https://stackoverflow.com/questions/51904495/
相关文章:
android - 如何在 Flutter 中让 Android 状态栏变亮
flutter - Flutter ListView、SliverList 等中的当前滚动偏移量
listview - Flutter - 容器 BoxShadow 在 ListView 中滚动时消
dart - Flutter 中的日期时间格式 dd/MM/YYYY hh :mm
flutter - 如何在 Flutter 中调整 IconButton 的大小(高度和宽度)
flutter - 在 Flutter 应用中立即显示应用主题