【问题标题】:How do you change the font size on a TextButton flutter如何更改 TextButton 颤动的字体大小
【发布时间】:2021-06-15 20:13:09
【问题描述】:

你会在这个例子中改变 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'),

【问题讨论】:

  • "fontSize" 在 Text() 小部件中使用 Text(style: TextStyle(fontSize: 25))

标签: flutter flutter-layout font-size


【解决方案1】:

请尝试

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),),
          )

【讨论】:

    【解决方案2】:
    SizedBox(
    
    height:100,
    width:100,
    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', style: TextStyle( fontSize: 30),
    

    ) )

    【讨论】:

    • 谢谢大家!知道怎么做就这么简单!
    猜你喜欢
    • 2018-12-03
    • 2020-05-17
    • 2022-10-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多