using hex colors in flutter code example
Example 1: how to use hexadecimal color in flutter
Color myColor = Color(0xff123456)
Example 2: flutter color hex
const color = const Color(0xffb74093);
Example 3: flutter hexadecimal color
extension HexColor on Color {
static Color fromHex(String hexString) {
final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
buffer.write(hexString.replaceFirst('#', ''));
return Color(int.parse(buffer.toString(), radix: 16));
}
String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
'${alpha.toRadixString(16).padLeft(2, '0')}'
'${red.toRadixString(16).padLeft(2, '0')}'
'${green.toRadixString(16).padLeft(2, '0')}'
'${blue.toRadixString(16).padLeft(2, '0')}';
}
Example 4: flutter hex color
Color myHexColor = Color(0xff123456)