From 01adae5b9d18beb22bdd70dd2969b8597be81335 Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Sun, 27 Sep 2026 00:59:40 +0700 Subject: [PATCH] fix(player): swipe left to advance and right to return --- lib/widgets/player_track_swipe.dart | 2 +- test/now_playing_lyrics_transition_test.dart | 6 ++++- test/player_track_swipe_test.dart | 25 +++++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/widgets/player_track_swipe.dart b/lib/widgets/player_track_swipe.dart index 0135537a..fb644da7 100644 --- a/lib/widgets/player_track_swipe.dart +++ b/lib/widgets/player_track_swipe.dart @@ -32,7 +32,7 @@ class _PlayerTrackSwipeState extends State MediaItem? _neighbor(double direction) { if (widget.currentIndex < 0) return null; - final at = widget.currentIndex + (direction > 0 ? 1 : -1); + final at = widget.currentIndex + (direction < 0 ? 1 : -1); return at >= 0 && at < widget.queue.length ? widget.queue[at] : null; } diff --git a/test/now_playing_lyrics_transition_test.dart b/test/now_playing_lyrics_transition_test.dart index 3605d17a..f696242e 100644 --- a/test/now_playing_lyrics_transition_test.dart +++ b/test/now_playing_lyrics_transition_test.dart @@ -200,13 +200,17 @@ void main() { .hitTestable(); final rect = tester.getRect(cover); final gesture = await tester.startGesture(rect.center); - await gesture.moveBy(const Offset(110, 0)); + await gesture.moveBy(const Offset(-110, 0)); await tester.pump(); expect(tester.getRect(cover), rect); await gesture.up(); await tester.pumpAndSettle(); expect(controller.selected, [1]); expect(find.text('Second').hitTestable(), findsOneWidget); + await tester.drag(cover, const Offset(110, 0)); + await tester.pumpAndSettle(); + expect(controller.selected, [1, 0]); + expect(find.text('First').hitTestable(), findsOneWidget); expect(tester.takeException(), isNull); }); } diff --git a/test/player_track_swipe_test.dart b/test/player_track_swipe_test.dart index db291d5c..3197440b 100644 --- a/test/player_track_swipe_test.dart +++ b/test/player_track_swipe_test.dart @@ -12,7 +12,7 @@ void main() { for (final reducedMotion in [false, true]) { testWidgets( - 'cover drag moves only titles and selects once ($reducedMotion)', + 'left swipe advances and right swipe returns without moving cover ($reducedMotion)', (tester) async { var index = 0; final selected = []; @@ -41,6 +41,7 @@ void main() { key: ValueKey('cover'), width: 200, height: 200, + child: ColoredBox(color: Colors.black), ), ), PlayerTrackSwipeTitles( @@ -68,27 +69,39 @@ void main() { final coverRect = tester.getRect(cover); final titleX = tester.getTopLeft(find.text('Song 0')).dx; final gesture = await tester.startGesture(coverRect.center); - await gesture.moveBy(const Offset(110, 0)); + await gesture.moveBy(const Offset(-110, 0)); await tester.pump(); expect(tester.getRect(cover), coverRect); - expect(tester.getTopLeft(find.text('Song 0')).dx, greaterThan(titleX)); + expect(tester.getTopLeft(find.text('Song 0')).dx, lessThan(titleX)); expect(find.text('Song 1'), findsOneWidget); await gesture.up(); await tester.pumpAndSettle(); expect(selected, [1]); expect(tester.getTopLeft(find.text('Song 1')).dx, closeTo(titleX, 0.1)); - await tester.drag(find.text('Song 1'), const Offset(-180, 0)); + await tester.drag(find.text('Song 1'), const Offset(180, 0)); await tester.pumpAndSettle(); expect(selected, [1, 0]); // At the first song the previous direction resists, then returns. - await tester.drag(cover, const Offset(-200, 0)); + await tester.drag(cover, const Offset(200, 0)); await tester.pumpAndSettle(); expect(selected, [1, 0]); expect(tester.getTopLeft(find.text('Song 0')).dx, closeTo(titleX, 0.1)); - await tester.drag(cover, const Offset(20, 0)); + await tester.drag(cover, const Offset(-20, 0)); await tester.pumpAndSettle(); expect(selected, [1, 0]); + await tester.drag(cover, const Offset(-200, 0)); + await tester.pumpAndSettle(); + await tester.drag(cover, const Offset(-200, 0)); + await tester.pumpAndSettle(); + expect(selected, [1, 0, 1, 2]); + // At the last song, only the next direction is blocked. + await tester.drag(cover, const Offset(-200, 0)); + await tester.pumpAndSettle(); + expect(selected, [1, 0, 1, 2]); + await tester.drag(cover, const Offset(200, 0)); + await tester.pumpAndSettle(); + expect(selected, [1, 0, 1, 2, 1]); expect(tester.takeException(), isNull); }, );