首页 > 解决方案 > 如何更改 TextButton 颤动的字体大小

问题描述

在这个例子中你会改变 Hello World 的字体大小吗?尝试了字体样式等但出现错误,请问我错过了什么?

new TextButton(
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.all<Color>(Colors.white.withOpacity(0.7)),
        overlayColor: MaterialStateProperty.resolveWith<Color>(
                (Set<MaterialState> states) {
              if (states.contains(MaterialState.focused) ||
                    states.contains(MaterialState.pressed))
                  return Colors.red.withOpacity(0.7);
                return Colors.red;
              return Colors.white70; // Defer to the widget's default.
            }
        ),
      ),
      child: new Text('Hello World'),

标签: flutterflutter-layoutfont-size

解决方案


请试用

TextButton(
            style: ButtonStyle(
              foregroundColor: MaterialStateProperty.all<Color>(
                  Colors.white.withOpacity(0.7)),
              overlayColor: MaterialStateProperty.resolveWith<Color>(
                  (Set<MaterialState> states) {
                if (states.contains(MaterialState.focused) ||
                    states.contains(MaterialState.pressed))
                  return Colors.red.withOpacity(0.7);
                return Colors.red; // Defer to the widget's default.
              return Colors.white70;
              }),
            ),
            child: new Text('Hello World', style: TextStyle( fontSize: 30),),
          )

推荐阅读