Skip to content

Commit

Permalink
Cancel animation when jumping in Date-/TimeController
Browse files Browse the repository at this point in the history
Closes #135
  • Loading branch information
JonasWanke committed Jan 24, 2023
1 parent 96a99c7 commit c0167c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/src/date/controller.dart
Expand Up @@ -91,7 +91,7 @@ class DateController extends ValueNotifier<DatePageValue> {
Duration duration = const Duration(milliseconds: 200),
required TickerProvider vsync,
}) async {
_animationController?.dispose();
cancelAnimation();
final controller =
AnimationController(debugLabel: 'DateController', vsync: vsync);
_animationController = controller;
Expand Down Expand Up @@ -120,10 +120,16 @@ class DateController extends ValueNotifier<DatePageValue> {
}

void jumpToPage(double page) {
cancelAnimation();
value =
value.copyWith(page: value.visibleRange.getTargetPageForFocus(page));
}

void cancelAnimation() {
_animationController?.dispose();
_animationController = null;
}

bool _isDisposed = false;
bool get isDisposed => _isDisposed;
@override
Expand Down
19 changes: 17 additions & 2 deletions lib/src/time/controller.dart
Expand Up @@ -191,7 +191,7 @@ class TimeController extends ValueNotifier<TimeRange> {
}) async {
assert(_isValidRange(newValue));

_animationController?.dispose();
cancelAnimation();
final previousRange = value;
_animationController =
AnimationController(debugLabel: 'TimeController', vsync: vsync)
Expand All @@ -205,7 +205,22 @@ class TimeController extends ValueNotifier<TimeRange> {
..animateTo(1, duration: duration, curve: curve);
}

void jumpToShowFullDay() => value = TimeRange.fullDay;
void jumpToShowFullDay() {
cancelAnimation();
value = TimeRange.fullDay;
}

void jumpTo(TimeRange range) {
assert(_isValidRange(range));

cancelAnimation();
value = range;
}

void cancelAnimation() {
_animationController?.dispose();
_animationController = null;
}
}

/// Provides the [TimeController] for Timetable widgets below it.
Expand Down

0 comments on commit c0167c2

Please sign in to comment.