Color对象
color是一个ARGB(A透明度,R就是red,G是gree,B是blue,RGB是光学三原色)格式的不可变的32位值.
例如flutter的logo,是完全不透明的,red部分值是0x42 (66),gree部分值是0xA5 (165),blue部分值是0xF5 (245)。在颜色值通用“哈希语法”中,它可以写为#42A5F5。
接下来是一些写法
Color c = const Color(0xFF42A5F5);
Color c = const Color.fromARGB(0xFF, 0x42, 0xA5, 0xF5);
Color c = const Color.fromARGB(255, 66, 165, 245);
Color c = const Color.fromRGBO(66, 165, 245, 1.0);如果在使用color时遇到没有渲染出来的问题,检查一下颜色值是8位16进制还是6位16进制。如果是6位16进制,会默认在前面补两个0,这样这个颜色就是完全透明了。
Color c1 = const Color(0xFFFFFF); // fully transparent white (invisible) 完全透明
Color c2 = const Color(0xFFFFFFFF); // fully opaque white (visible) 完全不透明同时colors里面定义了一些特殊的颜色类型
Implementers:
构造函数:
用int的低32位作为参数来构造颜色 const
Color.fromARGB(int a, int r, int g, int b)
用4个 int型的低8位整数作为参数来构造颜色 const
Color.fromRGBO(int r, int g, int b, double opacity)
用red,gree,blue,opacity(0到1的小数)作为参数来创建一个颜色对象,类似于css中rgba( ) const
属性:
hashCode → int:hash code 的值,只读, override
opacity → double:透明度的小数类型的值,只读
runtimeType → Type:对象的运行时类型,只读, inherited
方法:
computeLuminance( ) → double:返回0到1之间的亮度值,0表示最暗,1表示最亮
toString( ) → String:返回此对象的字符串表示形式 ,override
withAlpha(int a) → Color: 返回一个新的颜色,但透明度被传入的参数替换,参数的值区间在0到255
withBlue(int b) → Color:返回一个新的颜色,但blue部分被传入的参数替换,参数的值区间在0到255
withGreen(int g) → Color: 返回一个新的颜色,但gree部分被传入的参数替换,参数的值区间在0到255
withOpacity(double opacity) → Color: 返回一个新的颜色,但透明度被传入的参数替换,参数的值区间在0.0到1.0
withRed(int r) → Color: 返回一个新的颜色,但red部分被传入的参数替换,参数的值区间在0到255
noSuchMethod(Invocation invocation) → dynamic:访问不存在方法或属性时会调用该方法
运算子方法:
operator ==(dynamic other) → bool:覆盖双等号运算 ,override
静态方法:
alphaBlend(Color foreground, Color background) → Color:将第一个参数作为透明颜色覆盖到第二个参数上,返回组合成的颜色
lerp(Color a, Color b, double t) → Color:在两种颜色之间进行线性插值