validateAndConvertColor method

String validateAndConvertColor(
  1. String color
)

Implementation

String validateAndConvertColor(String color) {
  RegExp hexColorRegex =
      RegExp(r'^(#|0x|0X)?([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$');

  if (hexColorRegex.hasMatch(color)) {
    String formattedColor =
        color.replaceAll("#", "").replaceAll(RegExp(r'0x|0X'), '');
    if (formattedColor.length == 6) {
      formattedColor = "FF$formattedColor";
    }
    return "0x$formattedColor";
  } else {
    StatusHelper.failed('Format warna tidak valid: $color');
    return "Format warna tidak valid: $color";
  }
}