tick method

  1. @override
bool tick(
  1. double delta,
  2. Duration elapsed
)
override

Called each time there is an update from the ticker on the AnimatedBackground

The implementation must return true if there is a need to repaint and false otherwise.

Implementation

@override
bool tick(double delta, Duration elapsed) {
  final bool axisHorizontal =
      (direction == LineDirection.Ltr || direction == LineDirection.Rtl);
  final int sign =
      (direction == LineDirection.Ltr || direction == LineDirection.Ttb)
          ? 1
          : -1;
  if (axisHorizontal) {
    for (var line in lines!) {
      line.position =
          line.position!.translate(delta * line.speed * sign, 0.0);
      if ((direction == LineDirection.Ltr &&
              line.position!.dx > size!.width) ||
          (direction == LineDirection.Rtl && line.position!.dx < 0))
        initLine(line);
    }
  } else {
    for (var line in lines!) {
      line.position =
          line.position!.translate(0.0, delta * line.speed * sign);
      if ((direction == LineDirection.Ttb &&
              line.position!.dy > size!.height) ||
          (direction == LineDirection.Btt && line.position!.dy < 0))
        initLine(line);
    }
  }
  return true;
}