From fa738b9a9678dc21ff1f7c7f6df02eed4ccf0689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=BCllner?= Date: Thu, 5 Mar 2026 09:30:32 +0100 Subject: [PATCH] feat: add swipe navigation between main tabs --- lib/screens/home_shell.dart | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/screens/home_shell.dart b/lib/screens/home_shell.dart index 900bb73..aadc093 100644 --- a/lib/screens/home_shell.dart +++ b/lib/screens/home_shell.dart @@ -12,6 +12,8 @@ class HomeShell extends StatefulWidget { } class _HomeShellState extends State { + static const double _swipeVelocityThreshold = 300; + int _currentIndex = 0; final _collectionsKey = GlobalKey(); final _scanKey = GlobalKey(); @@ -26,12 +28,30 @@ class _HomeShellState extends State { setState(() => _currentIndex = i); } + void _handleHorizontalSwipe(DragEndDetails details) { + final velocity = details.primaryVelocity ?? 0; + if (velocity.abs() < _swipeVelocityThreshold) return; + + if (velocity < 0 && _currentIndex < _pages.length - 1) { + _onTabSelected(_currentIndex + 1); + return; + } + + if (velocity > 0 && _currentIndex > 0) { + _onTabSelected(_currentIndex - 1); + } + } + @override Widget build(BuildContext context) { return Scaffold( - body: IndexedStack( - index: _currentIndex, - children: _pages, + body: GestureDetector( + behavior: HitTestBehavior.translucent, + onHorizontalDragEnd: _handleHorizontalSwipe, + child: IndexedStack( + index: _currentIndex, + children: _pages, + ), ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex,