import 'package:flutter/animation.dart';
import 'package:lottie/lottie.dart';

extension LottieUtils on LottieComposition {
  Future<void> playBetween(
    AnimationController animationController,
    String markerStart, {
    String markerEnd = "",
    bool repeat = false,
  }) async {
    final startMarker = getMarker(markerStart)!.start;
    final endMarker = markerEnd == "" ? 1.0 : getMarker(markerEnd)!.start;
    final duration = this.duration * (endMarker - startMarker).abs();
    animationController.value = startMarker;
    if (repeat) {
      await animationController.repeat(
        min: startMarker,
        max: endMarker,
        period: duration,
      );
    } else {
      await animationController.animateTo(endMarker, duration: duration);
    }
  }
}