【问题标题】:Where to store shadow colors in ThemeData?ThemeData 在哪里存储阴影颜色?
【发布时间】:2020-06-08 06:48:23
【问题描述】:

1- 我有一个带有盒子阴影的容器,该阴影具有不同的颜色,具体取决于主题。我到底在哪里存储 ThemeData 中的阴影颜色?我将容器的颜色存储在 canvasColor 中,但我不确定将阴影颜色放在哪里。所以我可以轻松地做 Theme.of(context)...

2- 制作单独的主题时,我可以使用return ThemeData(myStuff); 而不是ThemeData().copyWith(myStuff); 吗?还是copyWith推荐的方式?

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:
    1. 通常您不会按主题更改阴影。如果是这样..您可以创建自己的类并在那里存储阴影。

      class MyShadows {
        static const primaryShadow =
          Shadow(color: Colors.black, blurRadius: 3, offset: Offset(2, 3));
      
       static const secondaryShadow =
         Shadow(color: Colors.black, blurRadius: 3, offset: Offset(2, 3));
      }
      
      ...
      Container(
        decoration: BoxDecoration(boxShadow: [MyShadows.primaryShadow]),
      );
      
    2. 没关系。当您执行 ThemeData() 时。 copyWith(yourStuff) - 创建 ThemeData 的新实例,然后通过调用 copyWith 从它创建另一个实例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 2015-07-14
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多