首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flutter从类调用textstyle的阴影小部件

flutter从类调用textstyle的阴影小部件
EN

Stack Overflow用户
提问于 2021-10-03 18:30:28
回答 2查看 26关注 0票数 0

我是flutter的新手,我想让代码尽可能少,所以我想调用它,但我不知道如何将shadow widget设置为固定变量

代码语言:javascript
复制
    class ShadowTextStyle extends TextStyle {
      final Color color;
      final FontWeight fontWeight;
      final double size;
      final List<Shadow>? shadows;
      const ShadowTextStyle({
        required this.color,
        required this.fontWeight,
        this.size = 14,
        this.shadows =//how to do it here,
        ,
    
      }): super(
            color: color,
            fontWeight: fontWeight,
            fontSize: size,
            shadows: shadows,
          );
    }

这是阴影参数,我想修复它

代码语言:javascript
复制
      shadows: <Shadow>[
        Shadow(
          offset: Offset(1.0, 0.0),
          blurRadius: 5.0,
          color: Color.fromARGB(255, 0, 0, 0),
        ),
      ],
EN

回答 2

Stack Overflow用户

发布于 2021-10-03 18:43:27

我不确定我的问题是否正确,但你可以将你的自定义阴影分配给一个变量,我总是有一个style.dart文件来保存我的自定义样式。

代码语言:javascript
复制
Shadow myShadow = Shadow(
  offset: Offset(1.0, 0.0),
  blurRadius: 5.0,
  color: Color.fromARGB(255, 0, 0, 0),
);
票数 0
EN

Stack Overflow用户

发布于 2021-10-04 07:07:16

我找到了。这就是我的意思:

代码语言:javascript
复制
const ShadowFile = <Shadow>[
  Shadow(
    offset: Offset(1.0, 0.0),
    blurRadius: 5.0,
    color: Color.fromARGB(255, 0, 0, 0),
  )
];

class ShadowTextStyle extends TextStyle {
  final Color color;
  final FontWeight fontWeight;
  final double size;
  const ShadowTextStyle({
    required this.color,
    required this.fontWeight,
    this.size = 14,
    shadows: ShadowFile,
  }) : super(
          color: color,
          fontWeight: fontWeight,
          fontSize: size,
         shadows: ShadowFile,
        );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69427749

复制
相关文章

相似问题

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