首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振TextStyle / fontSize

颤振TextStyle / fontSize
EN

Stack Overflow用户
提问于 2021-08-17 10:48:57
回答 3查看 406关注 0票数 0

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

要做到这一点,就必须做好准备。“

fontSize: Get.width * .030,

的附加代码,类似于颜色

{彩色= Colors.white}

这是我要定制的代码..。

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

它应该是这样的,但不幸的是,我不知道如何正确地把它组合起来

代码语言:javascript
复制
TextStyle _textStyle({Color color = Colors.white}{FontSize fontSize = Get.width * .030}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: fontSize,
    color: color,
    letterSpacing: 0.5,
  );
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-08-17 12:09:34

带有样式的文本类,

代码语言:javascript
复制
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,),
票数 0
EN

Stack Overflow用户

发布于 2021-08-17 11:37:27

需要将FontSize类型更改为double

代码语言:javascript
复制
TextStyle _textStyle({Color color = Colors.white ,double fontSize = Get.width * .030}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: fontSize,
    color: color,
    letterSpacing: 0.5,
  );
}```
票数 0
EN

Stack Overflow用户

发布于 2021-08-18 00:53:00

您能告诉我如何在"hintText:“中使用"TextField (”)吗?

当我这样做的时候

代码语言:javascript
复制
hintStyle: StyledText (
                  color: Colors.black,
                ),

那么我就得到了错误

“参数类型'StyledText‘不能分配给参数类型'TextStyle?’(文档)”

我已经修改了你的代码,使其工作到目前为止,再次感谢你的..只想与"hintStyle“一起使用

代码语言:javascript
复制
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,
  );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68815981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档