|
| 1 | +/* |
| 2 | + * Music Sharity - Share music across all platforms |
| 3 | + * Copyright (C) 2026 Sikelio (Byte Roast) |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +import 'package:flutter/material.dart'; |
| 19 | +import '../pages/home_page.dart'; |
| 20 | +import '../theme/app_theme.dart'; |
| 21 | + |
| 22 | +class MainScreen extends StatefulWidget { |
| 23 | + final String? initialLink; |
| 24 | + |
| 25 | + const MainScreen({super.key, this.initialLink}); |
| 26 | + |
| 27 | + @override |
| 28 | + State<MainScreen> createState() => _MainScreenState(); |
| 29 | +} |
| 30 | + |
| 31 | +class _MainScreenState extends State<MainScreen> { |
| 32 | + int _selectedIndex = 0; |
| 33 | + |
| 34 | + late List<Widget> _pages; |
| 35 | + |
| 36 | + @override |
| 37 | + void initState() { |
| 38 | + super.initState(); |
| 39 | + _pages = [ |
| 40 | + HomePage(initialLink: widget.initialLink, key: ValueKey(widget.initialLink)), |
| 41 | + Text('History') |
| 42 | + ]; |
| 43 | + } |
| 44 | + |
| 45 | + @override |
| 46 | + void didUpdateWidget(MainScreen oldWidget) { |
| 47 | + super.didUpdateWidget(oldWidget); |
| 48 | + |
| 49 | + if (widget.initialLink != oldWidget.initialLink) { |
| 50 | + _pages[0] = HomePage(initialLink: widget.initialLink, key: ValueKey(widget.initialLink)); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + void _onItemTapped(int index) { |
| 55 | + setState(() { |
| 56 | + _selectedIndex = index; |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + @override |
| 61 | + Widget build(BuildContext context) { |
| 62 | + return Scaffold( |
| 63 | + body: IndexedStack( |
| 64 | + index: _selectedIndex, |
| 65 | + children: _pages, |
| 66 | + ), |
| 67 | + bottomNavigationBar: BottomNavigationBar( |
| 68 | + currentIndex: _selectedIndex, |
| 69 | + onTap: _onItemTapped, |
| 70 | + fixedColor: AppTheme.electricBlue, |
| 71 | + items: const [ |
| 72 | + BottomNavigationBarItem( |
| 73 | + icon: Icon(Icons.home_rounded), |
| 74 | + label: 'Home', |
| 75 | + ), |
| 76 | + BottomNavigationBarItem( |
| 77 | + icon: Icon(Icons.history), |
| 78 | + label: 'History' |
| 79 | + ), |
| 80 | + ], |
| 81 | + ), |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
0 commit comments