Flutter 如何使用ThemeData backgroundColor获得颜色。蓝色[100]?
如何使用ThemeData backgroundColor获得颜色。蓝色[100] 我想我已经阅读了关于这个问题的所有内容,但它似乎并不能解决我的问题。我不想使用十六进制颜色 在“main”中,我对背景色的定义如下:Flutter 如何使用ThemeData backgroundColor获得颜色。蓝色[100]?,flutter,Flutter,如何使用ThemeData backgroundColor获得颜色。蓝色[100] 我想我已经阅读了关于这个问题的所有内容,但它似乎并不能解决我的问题。我不想使用十六进制颜色 在“main”中,我对背景色的定义如下: theme: ThemeData( backgroundColor: Colors.blue, ), MaterialColor _bgColor; ... _bgColor = Theme.of(widget.context).backgr
theme: ThemeData(
backgroundColor: Colors.blue,
),
MaterialColor _bgColor;
...
_bgColor = Theme.of(widget.context).backgroundColor;
theme: ThemeData(
backgroundColor: Colors.blue[100],
),
在我想使用此功能的程序中,我定义了MaterialColor并指定了一个值,如下所示:
theme: ThemeData(
backgroundColor: Colors.blue,
),
MaterialColor _bgColor;
...
_bgColor = Theme.of(widget.context).backgroundColor;
theme: ThemeData(
backgroundColor: Colors.blue[100],
),
这正如预期的那样有效
但是,我想使用的颜色是Colors.blue[100]。
如果我指定如下:
theme: ThemeData(
backgroundColor: Colors.blue,
),
MaterialColor _bgColor;
...
_bgColor = Theme.of(widget.context).backgroundColor;
theme: ThemeData(
backgroundColor: Colors.blue[100],
),
然后我得到运行时错误-类型“Color”不是类型“MaterialColor”的子类型。您可能需要导入MaterialColor
import 'package:flutter/material.dart';
我也有同样的问题,我找到了一个解决方法 总结 看起来这正按预期工作:
primarySwatch
采用ColorSwatch
,该材质颜色扩展。
色块是颜色的阴影贴图(从[50]到[900]
)
颜色。tea
l是一个样本,它包含了teal的所有不同颜色变化,其中teal[100]
只是其中之一
Colors.teal[100]
是一种单独的颜色,不能将其分配给需要完整样本的属性。不,我已经有了,只需要编译即可。Colors.blue[100]不能用在主题数据中,但必须有一种方法来获取它(我想),这就是我需要知道的。好的,我将主题颜色指定为Colors.blue,就像我在上面的第一个示例中所做的那样。那么我如何从我想做的事情中得到蓝色[100]?背景色:颜色。蓝色[100],材质颜色