File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
packages/netglade_flutter_utils/lib/src/extensions Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,16 @@ extension ColorExtensions on Color {
29
29
30
30
return Color (int .parse (value, radix: 16 ));
31
31
}
32
+
33
+ // ignore: prefer-boolean-prefixes, ok naming.
34
+ String toHexString ({bool includeSign = false , bool includeAlpha = true , bool asUpperCase = true }) {
35
+ final alpha = (a * 255 ).toInt ().toRadixString (16 ).padLeft (2 , '0' );
36
+ final red = (r * 255 ).toInt ().toRadixString (16 ).padLeft (2 , '0' );
37
+ final green = (g * 255 ).toInt ().toRadixString (16 ).padLeft (2 , '0' );
38
+ final blue = (b * 255 ).toInt ().toRadixString (16 ).padLeft (2 , '0' );
39
+
40
+ final result = '${includeSign ? '#' : '' }${includeAlpha ? alpha : '' }$red $green $blue ' ;
41
+
42
+ return asUpperCase ? result.toUpperCase () : result;
43
+ }
32
44
}
You can’t perform that action at this time.
0 commit comments