animateToHeight method

Future<void> animateToHeight(
  1. double targetHeight
)

Implementation

Future<void> animateToHeight(double targetHeight) async {
  double clampedHeight = targetHeight.clamp(0.1, 0.95);

  if ((bottomSliderHeight.value - clampedHeight).abs() < 0.01) {
    // إذا كان الفرق صغير جداً، لا حاجة للأنيميشن
    // If difference is very small, no need for animation
    return;
  }

  // إعداد الأنيميشن
  // Setup animation
  heightAnimation = Tween<double>(
    begin: bottomSliderHeight.value,
    end: clampedHeight,
  ).animate(CurvedAnimation(
    parent: heightController,
    curve: Curves.easeInOut,
  ));

  // إزالة listeners السابقة لتجنب memory leaks
  // Remove previous listeners to avoid memory leaks
  heightController.removeListener(() {});

  // إضافة listener جديد
  // Add new listener
  heightAnimation.addListener(() {
    bottomSliderHeight.value = heightAnimation.value;
  });

  // تشغيل الأنيميشن
  // Run animation
  heightController.reset();
  await heightController.forward();
}