@@ -100,12 +100,8 @@ class Color {
100
100
/// Color(0xFFFF9000)` (` FF` for the alpha, ` FF` for the red, ` 90` for the
101
101
/// green, and `00` for the blue).
102
102
const Color (int value)
103
- : _value = value & 0xFFFFFFFF ,
104
- colorSpace = ColorSpace .sRGB,
105
- _a = null ,
106
- _r = null ,
107
- _g = null ,
108
- _b = null ;
103
+ : this ._fromARGBC (
104
+ value >> 24 , value >> 16 , value >> 8 , value, ColorSpace .sRGB);
109
105
110
106
/// Construct a color with normalized color components.
111
107
///
@@ -118,11 +114,10 @@ class Color {
118
114
required double green,
119
115
required double blue,
120
116
this .colorSpace = ColorSpace .sRGB})
121
- : _value = 0 ,
122
- _a = alpha,
123
- _r = red,
124
- _g = green,
125
- _b = blue;
117
+ : a = alpha,
118
+ r = red,
119
+ g = green,
120
+ b = blue;
126
121
127
122
/// Construct an sRGB color from the lower 8 bits of four integers.
128
123
///
@@ -137,28 +132,12 @@ class Color {
137
132
/// See also [fromRGBO] , which takes the alpha value as a floating point
138
133
/// value.
139
134
const Color .fromARGB (int a, int r, int g, int b)
140
- : _value = (((a & 0xff ) << 24 ) |
141
- ((r & 0xff ) << 16 ) |
142
- ((g & 0xff ) << 8 ) |
143
- ((b & 0xff ) << 0 )) &
144
- 0xFFFFFFFF ,
145
- colorSpace = ColorSpace .sRGB,
146
- _a = null ,
147
- _r = null ,
148
- _g = null ,
149
- _b = null ;
135
+ : this ._fromARGBC (a, r, g, b, ColorSpace .sRGB);
150
136
151
137
const Color ._fromARGBC (
152
- int alpha, int red, int green, int blue, this .colorSpace)
153
- : _value = (((alpha & 0xff ) << 24 ) |
154
- ((red & 0xff ) << 16 ) |
155
- ((green & 0xff ) << 8 ) |
156
- ((blue & 0xff ) << 0 )) &
157
- 0xFFFFFFFF ,
158
- _a = null ,
159
- _r = null ,
160
- _g = null ,
161
- _b = null ;
138
+ int alpha, int red, int green, int blue, ColorSpace colorSpace)
139
+ : this ._fromRGBOC (
140
+ red, green, blue, (alpha & 0xff ) / 255 , colorSpace);
162
141
163
142
/// Create an sRGB color from red, green, blue, and opacity, similar to
164
143
/// `rgba()` in CSS.
@@ -173,41 +152,34 @@ class Color {
173
152
///
174
153
/// See also [fromARGB] , which takes the opacity as an integer value.
175
154
const Color .fromRGBO (int r, int g, int b, double opacity)
176
- : _value = ((((opacity * 0xff ~ / 1 ) & 0xff ) << 24 ) |
177
- ((r & 0xff ) << 16 ) |
178
- ((g & 0xff ) << 8 ) |
179
- ((b & 0xff ) << 0 )) &
180
- 0xFFFFFFFF ,
181
- colorSpace = ColorSpace .sRGB,
182
- _a = null ,
183
- _r = null ,
184
- _g = null ,
185
- _b = null ;
155
+ : this ._fromRGBOC (r, g, b, opacity, ColorSpace .sRGB);
156
+
157
+ const Color ._fromRGBOC (int r, int g, int b, double opacity, this .colorSpace)
158
+ : a = opacity,
159
+ r = (r & 0xff ) / 255 ,
160
+ g = (g & 0xff ) / 255 ,
161
+ b = (b & 0xff ) / 255 ;
186
162
187
163
/// The alpha channel of this color.
188
164
///
189
165
/// A value of 0.0 means this color is fully transparent. A value of 1.0 means
190
166
/// this color is fully opaque.
191
- double get a => _a ?? (alpha / 255 );
192
- final double ? _a;
167
+ final double a;
193
168
194
169
/// The red channel of this color.
195
- double get r => _r ?? (red / 255 );
196
- final double ? _r;
170
+ final double r;
197
171
198
172
/// The green channel of this color.
199
- double get g => _g ?? (green / 255 );
200
- final double ? _g;
173
+ final double g;
201
174
202
175
/// The blue channel of this color.
203
- double get b => _b ?? (blue / 255 );
204
- final double ? _b;
176
+ final double b;
205
177
206
178
/// The color space of this color.
207
179
final ColorSpace colorSpace;
208
180
209
181
static int _floatToInt8 (double x) {
210
- return (( x * 255.0 ).round () ) & 0xff ;
182
+ return (x * 255.0 ).round () & 0xff ;
211
183
}
212
184
213
185
/// A 32 bit value representing this color.
@@ -220,16 +192,11 @@ class Color {
220
192
/// * Bits 0-7 are the blue value.
221
193
@Deprecated ('Use component accessors like .r or .g.' )
222
194
int get value {
223
- if (_a != null && _r != null && _g != null && _b != null ) {
224
- return _floatToInt8 (_a) << 24 |
225
- _floatToInt8 (_r) << 16 |
226
- _floatToInt8 (_g) << 8 |
227
- _floatToInt8 (_b) << 0 ;
228
- } else {
229
- return _value;
230
- }
195
+ return _floatToInt8 (a) << 24 |
196
+ _floatToInt8 (r) << 16 |
197
+ _floatToInt8 (g) << 8 |
198
+ _floatToInt8 (b) << 0 ;
231
199
}
232
- final int _value;
233
200
234
201
/// The alpha channel of this color in an 8 bit value.
235
202
///
0 commit comments