Skip to content

Feat : Add timed auto-sliding feature for intro pages #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/src/animation_gesture/animated_page_dragger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AnimatedPageDragger {
required double slidePercent,
required StreamController<SlideUpdate> slideUpdateStream,
required TickerProvider vsync,
this.autoSlideDuration = const Duration(seconds: 3),
}) {
final startSlidePercent = slidePercent;
double endSlidePercent;
Expand Down Expand Up @@ -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();
}
}
});
}
Expand All @@ -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();
}
}
32 changes: 32 additions & 0 deletions lib/src/controllers/auto_slide_controller.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}