在ThemeData中将阴影颜色存储在哪里?

时间:2020-06-08 06:48:23

标签: flutter flutter-layout

1-我有一个带有框阴影的容器,该阴影根据主题而具有不同的颜色。我到底将阴影颜色存储在ThemeData中的什么位置?我将容器的颜色存储在canvasColor中,但不确定将阴影颜色放在何处。所以我可以轻松地执行Theme.of(context)...

2-制作单独的主题时,如果我return ThemeData(myStuff);而不是ThemeData().copyWith(myStuff);可以吗?还是采用建议的方式进行复制?

1 个答案:

答案 0 :(得分: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

  3. 从中创建另一个实例