loop method

TickerFuture loop({
  1. int? count,
  2. bool reverse = false,
  3. double? min,
  4. double? max,
  5. Duration? period,
})

Implementation

TickerFuture loop({
  int? count,
  bool reverse = false,
  double? min,
  double? max,
  Duration? period,
}) {
  assert(count == null || count >= 0);
  assert(period != null || duration != null);

  min ??= lowerBound;
  max ??= upperBound;
  period ??= duration;

  if (count == 0) return animateTo(min, duration: Duration.zero);

  final tickerFuture = repeat(
    min: min,
    max: max,
    reverse: reverse,
    period: period,
  );

  if (count != null) {
    // timeout ~1 tick before it should complete (@120hz):
    int t = period!.inMilliseconds * count - 8;
    tickerFuture.timeout(Duration(milliseconds: t), onTimeout: () async {
      animateTo(reverse && count.isEven ? min! : max!);
    });
  }

  return tickerFuture;
}