From ef651c612131052653fae23f71244c4320376b54 Mon Sep 17 00:00:00 2001 From: oussama berhili Date: Mon, 20 Jan 2025 15:52:04 +0100 Subject: [PATCH] refactor: update build scripts and enhance auto-slide functionality - Changed task registration method in `build.gradle` for cleaner syntax. - Updated `minSdkVersion` in `app/build.gradle` to use a variable for better maintainability. - Added support for FFI plugins in `generated_plugins.cmake` for both Linux and Windows platforms. - Enhanced `AnimatedPageDragger` class to include auto-slide functionality with configurable duration. These changes improve build configuration and enhance the user experience with new animation features. --- .../animated_page_dragger.dart | 33 +++++++++++++++++++ .../controllers/auto_slide_controller.dart | 32 ++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 lib/src/controllers/auto_slide_controller.dart diff --git a/lib/src/animation_gesture/animated_page_dragger.dart b/lib/src/animation_gesture/animated_page_dragger.dart index 34df9d5..46fba0f 100644 --- a/lib/src/animation_gesture/animated_page_dragger.dart +++ b/lib/src/animation_gesture/animated_page_dragger.dart @@ -15,6 +15,7 @@ class AnimatedPageDragger { required double slidePercent, required StreamController slideUpdateStream, required TickerProvider vsync, + this.autoSlideDuration = const Duration(seconds: 3), }) { final startSlidePercent = slidePercent; double endSlidePercent; @@ -56,6 +57,11 @@ class AnimatedPageDragger { // Adding to slide update stream slideUpdateStream.add(SlideUpdate( slideDirection, slidePercent, UpdateType.doneAnimating)); + + // Start auto-slide timer after animation completes + if (_autoSlideEnabled) { + _startAutoSlideTimer(); + } } }); } @@ -68,13 +74,40 @@ class AnimatedPageDragger { /// Animation controller. late AnimationController completionAnimationController; + final Duration autoSlideDuration; + + // Add new fields for auto-slide functionality + Timer? _autoSlideTimer; + bool _autoSlideEnabled = false; + /// This method is used to run animation controller. void run() { completionAnimationController.forward(from: 0.0); } + // Add new methods for auto-slide control + void startAutoSlide() { + _autoSlideEnabled = true; + _startAutoSlideTimer(); + } + + void stopAutoSlide() { + _autoSlideEnabled = false; + _autoSlideTimer?.cancel(); + } + + void _startAutoSlideTimer() { + _autoSlideTimer?.cancel(); + _autoSlideTimer = Timer(autoSlideDuration, () { + if (_autoSlideEnabled) { + run(); + } + }); + } + /// This method is used to dispose animation controller. void dispose() { + _autoSlideTimer?.cancel(); completionAnimationController.dispose(); } } diff --git a/lib/src/controllers/auto_slide_controller.dart b/lib/src/controllers/auto_slide_controller.dart new file mode 100644 index 0000000..1441b3d --- /dev/null +++ b/lib/src/controllers/auto_slide_controller.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; + +class AutoSlideController extends ChangeNotifier { + bool _isAutoSliding = false; + Duration _slideDuration; + + AutoSlideController({Duration slideDuration = const Duration(seconds: 3)}) + : _slideDuration = slideDuration; + + bool get isAutoSliding => _isAutoSliding; + Duration get slideDuration => _slideDuration; + + void startAutoSlide() { + _isAutoSliding = true; + notifyListeners(); + } + + void stopAutoSlide() { + _isAutoSliding = false; + notifyListeners(); + } + + void setSlideDuration(Duration duration) { + _slideDuration = duration; + notifyListeners(); + } + + void toggleAutoSlide() { + _isAutoSliding = !_isAutoSliding; + notifyListeners(); + } +}