import 'package:flutter/material.dart'; import 'collections_screen.dart'; import 'scan_tab.dart'; import 'profile_screen.dart'; /// Bottom-navigation shell that hosts the three main tabs. class HomeShell extends StatefulWidget { const HomeShell({super.key}); @override State createState() => _HomeShellState(); } class _HomeShellState extends State { static const double _swipeVelocityThreshold = 300; int _currentIndex = 0; final _collectionsKey = GlobalKey(); final _scanKey = GlobalKey(); late final List _pages = [ CollectionsScreen(key: _collectionsKey), ScanTab(key: _scanKey), const ProfileScreen(), ]; void _onTabSelected(int i) { 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: GestureDetector( behavior: HitTestBehavior.translucent, onHorizontalDragEnd: _handleHorizontalSwipe, child: IndexedStack( index: _currentIndex, children: _pages, ), ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex, onDestinationSelected: _onTabSelected, destinations: const [ NavigationDestination( icon: Icon(Icons.collections_bookmark_outlined), selectedIcon: Icon(Icons.collections_bookmark), label: 'Collections', ), NavigationDestination( icon: Icon(Icons.qr_code_scanner_outlined), selectedIcon: Icon(Icons.qr_code_scanner), label: 'Scan', ), NavigationDestination( icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: 'Profile', ), ], ), ); } }