changeBackground method

void changeBackground({
  1. PlaygroundBackground? background,
})

Implementation

void changeBackground({PlaygroundBackground? background}) {
  if (background != null && background is PhotoBackground) {
    value = value.copyWith(background: background);
  } else {
    final current = value.background;
    final index = value.background is GradientBackground
        ? gradients.indexOf(current as GradientBackground)
        : 0;
    final hasMatch = index != -1;
    final nextIndex =
        hasMatch && index + 1 < gradients.length ? index + 1 : 0;
    final bg = gradients[nextIndex];
    value = value.copyWith(background: bg, textBackground: bg);
  }
}