diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bddf39..ca89691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.1.1 + +- **Bug Fixes**: + - Fixed `AnimationController.reverse() called after AnimationController.dispose()` when a page with a + `RoundScrollbar` is closed before the auto-hide duration elapses. The fade-out timer is now cancelled in + `dispose()` and its callback checks `mounted`. + ## 1.1.0 - **Bug Fixes**: diff --git a/lib/widgets/round_scrollbar.dart b/lib/widgets/round_scrollbar.dart index 9764465..04e406b 100644 --- a/lib/widgets/round_scrollbar.dart +++ b/lib/widgets/round_scrollbar.dart @@ -169,7 +169,9 @@ class _RoundScrollbarState extends State _fadeOutTimer?.cancel(); if (!widget.autoHide) return; _fadeOutTimer = Timer(widget.autoHideDuration, () { - _opacityController.reverse(); + if (mounted) { + _opacityController.reverse(); + } _fadeOutTimer = null; }); } @@ -243,6 +245,7 @@ class _RoundScrollbarState extends State @override void dispose() { + _fadeOutTimer?.cancel(); _currentController?.removeListener(_onScroll); _opacityController.dispose(); super.dispose(); diff --git a/pubspec.yaml b/pubspec.yaml index fac7877..c79f799 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rotary_scrollbar description: circular scrollbar for Wear OS devices. It can be controlled with rotary input and it includes haptic feedback. -version: 1.1.0 +version: 1.1.1 homepage: https://github.com/hyperfluid-tech/rotary_scrollbar environment: diff --git a/test/round_scrollbar_test.dart b/test/round_scrollbar_test.dart index 85a9636..8f5fc19 100644 --- a/test/round_scrollbar_test.dart +++ b/test/round_scrollbar_test.dart @@ -184,6 +184,26 @@ void main() { ); }); + group('Lifecycle', () { + testWidgets( + 'GIVEN visible scrollbar ' + 'WHEN it is disposed before the autoHide duration elapses ' + 'THEN the pending fade-out does not touch the disposed controller', + (tester) async { + // Arrange + await setUpWidget(tester); + await tester.pumpAndSettle(defaultOpacityDuration); // Fade in + + // Act - leave the page while the fade-out timer is pending + await tester.pumpWidget(const SizedBox()); + await tester.pump(defaultAutoHideDuration); + + // Assert + expect(tester.takeException(), isNull); + }, + ); + }); + group('Animation control', () { group('Fade in animation', () { testWidgets(