有人知道当按下按钮时如何改变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;
                });
              },
            )
          ],
        ));
  }

也许你想改变sibling 姐妹的文字.概念是一样的.快乐的飞翔

Flutter相关问答推荐

为什么我需要等待重新访问Firestore数据库,即使它已经做了之前?

Flutter—如何在Riverpod中使用全类状态?

SingleChildScrollView正在将Container的高度限制为子对象,尽管使用了Expanded Inside Row()

Flutter creating Constant.dart InputDecoration section put pass in hintText

无法构建AndroidBundle 包或iOS等

在Flutter 中创建自定义形状

Flutter守护进程无法启动

导航回上一页会将我带回Ffltter应用程序中的登录页面

无法应用插件com.chaquo.python

自定义绘画未显示 - Flutter

创建混合 TextWidget 和 TextFieldWidget

升级到 Flutter 3.10 后,Flutter 键盘填充不起作用. Flutter 3.10 如何防止 BottomSheet 被键盘覆盖?

Flutter Firebase 升级后出现问题? ARC 语义问题 (Xcode): Select 器appleCredentialWithIDToken:rawNonce:fullName:没有已知的类方法

Flutter:如何从运行时创建的列表中访问单个子部件的值

如何让小部件根据小部件的大小构建不同的布局?

Flutter ListView 在 Column 中工作但在 Row 中不工作

在提供程序包更改通知程序中构建倒计时时钟

如何格式化网址?

SfCircularChart 周围的额外间距

如何将所有行项目平等地放在一行中?Flutter