withStateLayer function

Color withStateLayer(
  1. Color fill,
  2. Color label,
  3. double opacity
)

fill with its contrast-safe state layer (stateLayerColor) at opacity composited on.

Implementation

Color withStateLayer(Color fill, Color label, double opacity) => opacity <= 0
    ? fill
    : Color.alphaBlend(
        stateLayerColor(fill, label).withValues(alpha: opacity.clamp(0.0, 1.0)),
        fill,
      );