Open ambrose-gladwell-sonocent opened 1 month ago
10.8.4
8 digit hex color codes should be supported and displayed correctly. Quill JS supports this so it would be nice if this library did also
8 digit hex color code is not recognised mathced in the regex used in the hexToColor method in colour_button.dart instead it return Colors.black.
hexToColor
colour_button.dart
Colors.black
Potential fixed hexToColor code which support 3, 6 and 8 digit hex colour codes:
Color hexToColor(String? hexString) { if (hexString == null) { return Colors.black; } final hexRegex = RegExp(r'^[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8}$'); hexString = hexString.replaceAll('#', ''); if (!hexRegex.hasMatch(hexString)) { return Colors.black; } final buffer = StringBuffer(); if (hexString.length == 3) { hexString = hexString.split('').map((char) => char * 2).join(''); } if (hexString.length == 6) { buffer.write('ff'); } buffer.write(hexString); return Color(int.tryParse(buffer.toString(), radix: 16) ?? 0xFF000000); }
Is there an existing issue for this?
Flutter Quill version
10.8.4
Steps to reproduce
Expected results
8 digit hex color codes should be supported and displayed correctly. Quill JS supports this so it would be nice if this library did also
Actual results
8 digit hex color code is not recognised mathced in the regex used in the
hexToColor
method incolour_button.dart
instead it returnColors.black
.Additional Context
Potential fixed
hexToColor
code which support 3, 6 and 8 digit hex colour codes: