withOpacity static method

String withOpacity(
  1. String color,
  2. double opacity
)

Implementation

static String withOpacity(String color, double opacity) {
  if (color.startsWith('#')) {
    final hex = color.substring(1);
    final r = int.parse(hex.substring(0, 2), radix: 16);
    final g = int.parse(hex.substring(2, 4), radix: 16);
    final b = int.parse(hex.substring(4, 6), radix: 16);
    return 'rgba($r, $g, $b, $opacity)';
  }
  return color;
}