customBadgeBacking method

Decoration customBadgeBacking()

Implementation

Decoration customBadgeBacking() {
  var baseDecoration =
      BaseBackingDecoration(decorationVariant: decorationPriority.standard);
  Gradient backingGradient = const LinearGradient(colors: []);
  BoxShadow backingHaze = const BoxShadow();
  baseDecoration.decorationCornerRadius = BorderRadius.circular(60.0);

  switch (badgePriority) {
    case decorationPriority.inactive:
      {
        /*

          Since the badges are supposed to be used on top of
          important elements, inactive elements will show
          as the fill of the opposite mode's fill color to
          preserve contrast (since layering the mode's fill)
          on an important priority item will lead to the
          background looking invisible.

           */

        baseDecoration.decorationFill =
            palette.brightness() == Brightness.light
                ? palette.lightModeFill()
                : palette.darkModeFill();

        break;
      }

    case decorationPriority.important:
      {
        backingGradient = palette.brightness() == Brightness.light
            ? palette.darkGradient()
            : palette.lightGradient();

        backingHaze = palette.brightness() == Brightness.light
            ? palette.pastelShadow()
            : palette.darkShadow();

        baseDecoration.decorationGradient = backingGradient;
        baseDecoration.decorationHaze = backingHaze;
        break;
      }

    case decorationPriority.standard:
      {
        baseDecoration.decorationFill = coloration.inactiveColor();
        break;
      }

    case decorationPriority.inverted:
      {
        backingGradient = palette.brightness() == Brightness.light
            ? palette.lightGradient()
            : palette.darkGradient();

        backingHaze = palette.brightness() == Brightness.light
            ? palette.pastelShadow()
            : palette.darkShadow();

        baseDecoration.decorationGradient = backingGradient;
        baseDecoration.decorationHaze = backingHaze;
        break;
      }

    case decorationPriority.active:
      {
        throw ("BadgeElement cannot be decorationPriority.active, that priority is meant for interactable elements being highlighted and BadgeElement is non-interactable.");
      }
  }

  return baseDecoration.buildBacking();
}