File tree Expand file tree Collapse file tree 2 files changed +1075
-0
lines changed Expand file tree Collapse file tree 2 files changed +1075
-0
lines changed Original file line number Diff line number Diff line change @@ -47,4 +47,30 @@ extension ColorExtension on Color {
47
47
/// Converts opacity value to color with alpha
48
48
/// This avoids using the deprecated overlayOpacity directly
49
49
Color reduceOpacity (double opacity) => withAlpha ((opacity * 255 ).round ());
50
+
51
+ /// Safe replacement for deprecated red property
52
+ int get safeRed => (0x00ff0000 & _toARGB32 ()) >> 16 ;
53
+
54
+ /// Safe replacement for deprecated green property
55
+ int get safeGreen => (0x0000ff00 & _toARGB32 ()) >> 8 ;
56
+
57
+ /// Safe replacement for deprecated blue property
58
+ int get safeBlue => (0x000000ff & _toARGB32 ()) >> 0 ;
59
+
60
+ /// Safe replacement for deprecated opacity property
61
+ double get safeOpacity => safeAlpha / 0xFF ;
62
+
63
+ /// Safe replacement for deprecated alpha property
64
+ int get safeAlpha => (0xff000000 & _toARGB32 ()) >> 24 ;
65
+
66
+ int _toARGB32 () {
67
+ return _floatToInt8 (a) << 24 |
68
+ _floatToInt8 (r) << 16 |
69
+ _floatToInt8 (g) << 8 |
70
+ _floatToInt8 (b) << 0 ;
71
+ }
72
+
73
+ int _floatToInt8 (double x) {
74
+ return (x * 255.0 ).round () & 0xff ;
75
+ }
50
76
}
You can’t perform that action at this time.
0 commit comments