【问题标题】:Flutter TextStyle / fontSizeFlutter TextStyle / fontSize
【发布时间】:2021-10-19 06:45:11
【问题描述】:

我想要 TextStyle / fontSize 来简化我的应用程序。

为此,有必要将行“

fontSize: Get.width * .030,

" 附上可用的代码,类似颜色"

{颜色颜色 = Colors.white}

这是我要自定义的代码...

TextStyle _textStyle({Color color = Colors.white}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: Get.width * .030,
    color: color,
    letterSpacing: 0.5,
  );
}

它应该看起来像这样,但不幸的是我不知道如何正确地将它组合在一起

TextStyle _textStyle({Color color = Colors.white}{FontSize fontSize = Get.width * .030}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: fontSize,
    color: color,
    letterSpacing: 0.5,
  );
}

【问题讨论】:

    标签: flutter textstyle


    【解决方案1】:

    带样式的文本类,

    class StoryText extends Text {
      StoryText(String title, {Color mColor, double mFontSize})
          : super(title,
                style: GoogleFonts.getFont(
                  'Unica One',
                  fontSize: mFontSize,
                  color: mColor,
                  letterSpacing: 0.5,
                ));
    }
    
    // Use of above class
    StoryText('title', mColor: Colors.red, mFontSize: Get.width * .030,),
    

    【讨论】:

    • 非常感谢 :) ❤?
    【解决方案2】:

    需要将FontSize类型改为double

    TextStyle _textStyle({Color color = Colors.white ,double fontSize = Get.width * .030}) {
      return GoogleFonts.getFont(
        'Unica One',
        fontSize: fontSize,
        color: color,
        letterSpacing: 0.5,
      );
    }```
    

    【讨论】:

      【解决方案3】:

      你能告诉我如何在“TextField (”的“hintText:”中使用它吗?

      当我这样做时

      hintStyle: StyledText (
                        color: Colors.black,
                      ),
      

      然后我得到错误

      "参数类型'StyledText'不能赋值给参数 键入“文本样式?”。 (文档)”

      我已经修改了您的代码,使其到目前为止仍然有效,再次感谢您? .. 只想将它与“hintStyle”一起使用

      import 'package: flutter / cupertino.dart';
      import 'package: flutter / material.dart';
      import 'package: google_fonts / google_fonts.dart';
      
      class StyledText extends Text {
        StyledText (
            String title,
            {
              double fontSize = 10.5,
              color = Colors.white,
              fontWeight = FontWeight.w100,
              letterSpacing = 0.5,
              textAlign: TextAlign.center,
            })
            : super (title,
            style: GoogleFonts.getFont (
              'Unica One',
              fontSize: fontSize,
              color: color,
              fontWeight: fontWeight,
              letterSpacing: 0.5,
            ),
          textAlign: textAlign,
        );
      }
      

      【讨论】:

        猜你喜欢
        • 2019-12-07
        • 2021-02-28
        • 1970-01-01
        • 2021-10-19
        • 1970-01-01
        • 2020-02-04
        • 2021-11-27
        • 1970-01-01
        • 2021-02-24
        相关资源
        最近更新 更多