Skip to content

Commit aa84c53

Browse files
committed
test: 🧪 Added tests for Overlay
1 parent 43c03f7 commit aa84c53

File tree

2 files changed

+1075
-0
lines changed

2 files changed

+1075
-0
lines changed

lib/src/utils/extensions.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,30 @@ extension ColorExtension on Color {
4747
/// Converts opacity value to color with alpha
4848
/// This avoids using the deprecated overlayOpacity directly
4949
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+
}
5076
}

0 commit comments

Comments
 (0)