我的应用程序中有一个Container-Widget 我想用一个LinearGradient应该改变他的颜色来装饰,这取决于当前的ThemeData.
轻型版:
static const gradientBlue = LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: <Color>[_gradientPurple, _gradientBlue, _gradientNeon],
);
黑暗版:
static const gradientBlueDark = LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
colors: <Color>[_gradientGreen, _gradientBlack],
);
都存储在我的CustomColors课堂上。
利用:
...Container(
decoration: BoxDecoration(gradient: CustomColors.gradientBlue),
child:....
对于我来说MaterialApp,我使用两个自定义 ThemeDatatheme:和darkTheme:. 因此,当手机进入黑暗模式并返回时,一切都会改变他的颜色,除了我不知道如何存储这两个版本的渐变,例如Theme.of(context).gradientBlue,因为你不能在ThemeData.
任何解决方法?