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