import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:spotiflac_android/providers/download_queue_provider.dart'; import 'package:spotiflac_android/screens/home_tab.dart'; import 'package:spotiflac_android/screens/queue_tab.dart'; import 'package:spotiflac_android/screens/settings_tab.dart'; class MainShell extends ConsumerStatefulWidget { const MainShell({super.key}); @override ConsumerState createState() => _MainShellState(); } class _MainShellState extends ConsumerState { int _currentIndex = 0; late PageController _pageController; @override void initState() { super.initState(); _pageController = PageController(initialPage: _currentIndex); } @override void dispose() { _pageController.dispose(); super.dispose(); } void _onNavTap(int index) { setState(() => _currentIndex = index); _pageController.animateToPage( index, duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, ); } void _onPageChanged(int index) { setState(() => _currentIndex = index); } @override Widget build(BuildContext context) { final queueState = ref.watch(downloadQueueProvider); return Scaffold( appBar: AppBar( leading: Padding( padding: const EdgeInsets.all(8.0), child: ClipRRect( borderRadius: BorderRadius.circular(20), child: Image.asset( 'assets/images/logo.png', width: 40, height: 40, ), ), ), title: const Text('SpotiFLAC'), ), body: PageView( controller: _pageController, onPageChanged: _onPageChanged, physics: const BouncingScrollPhysics(), children: const [ HomeTab(), QueueTab(), SettingsTab(), ], ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex, onDestinationSelected: _onNavTap, animationDuration: const Duration(milliseconds: 300), destinations: [ const NavigationDestination( icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: 'Home', ), NavigationDestination( icon: Badge( isLabelVisible: queueState.queuedCount > 0, label: Text('${queueState.queuedCount}'), child: const Icon(Icons.download_outlined), ), selectedIcon: Badge( isLabelVisible: queueState.queuedCount > 0, label: Text('${queueState.queuedCount}'), child: const Icon(Icons.download), ), label: 'Downloads', ), const NavigationDestination( icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: 'Settings', ), ], ), ); } }