feat: add swipe navigation between main tabs

This commit is contained in:
Lukas Müllner 2026-03-05 09:30:32 +01:00
parent f03f1b18e4
commit fa738b9a96

View file

@ -12,6 +12,8 @@ class HomeShell extends StatefulWidget {
}
class _HomeShellState extends State<HomeShell> {
static const double _swipeVelocityThreshold = 300;
int _currentIndex = 0;
final _collectionsKey = GlobalKey<CollectionsScreenState>();
final _scanKey = GlobalKey<ScanTabState>();
@ -26,12 +28,30 @@ class _HomeShellState extends State<HomeShell> {
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,