mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
136 lines
4.1 KiB
Dart
136 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../core/constants/app_constants.dart';
|
|
import '../../core/constants/app_icons.dart';
|
|
import '../../core/widgets/mini_player.dart';
|
|
|
|
class MainNavigation extends StatefulWidget {
|
|
final Widget child;
|
|
|
|
const MainNavigation({
|
|
super.key,
|
|
required this.child,
|
|
});
|
|
|
|
@override
|
|
State<MainNavigation> createState() => _MainNavigationState();
|
|
}
|
|
|
|
class _MainNavigationState extends State<MainNavigation> {
|
|
int _currentIndex = 0;
|
|
|
|
final List<NavigationItem> _navigationItems = [
|
|
NavigationItem(
|
|
icon: AppIcons.home,
|
|
selectedIcon: AppIcons.homeFilled,
|
|
label: 'Home',
|
|
route: AppConstants.homeRoute,
|
|
),
|
|
NavigationItem(
|
|
icon: AppIcons.search,
|
|
selectedIcon: AppIcons.searchFilled,
|
|
label: 'Search',
|
|
route: AppConstants.searchRoute,
|
|
),
|
|
NavigationItem(
|
|
icon: AppIcons.library,
|
|
selectedIcon: AppIcons.libraryFilled,
|
|
label: 'Library',
|
|
route: AppConstants.libraryRoute,
|
|
),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: widget.child,
|
|
),
|
|
const MiniPlayer(),
|
|
],
|
|
),
|
|
bottomNavigationBar: Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Theme.of(context).shadowColor.withValues(alpha: 0.1),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, -2),
|
|
),
|
|
],
|
|
),
|
|
child: SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: _navigationItems.map((item) {
|
|
final isSelected = _currentIndex == _navigationItems.indexOf(item);
|
|
return Expanded(
|
|
child: InkWell(
|
|
onTap: () => _onItemTapped(_navigationItems.indexOf(item)),
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(
|
|
isSelected ? item.selectedIcon : item.icon,
|
|
color: isSelected
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6),
|
|
size: 24,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
item.label,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: isSelected
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.6),
|
|
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w500,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onItemTapped(int index) {
|
|
final item = _navigationItems[index];
|
|
if (_currentIndex != index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
context.go(item.route);
|
|
}
|
|
}
|
|
}
|
|
|
|
class NavigationItem {
|
|
final IconData icon;
|
|
final IconData selectedIcon;
|
|
final String label;
|
|
final String route;
|
|
|
|
NavigationItem({
|
|
required this.icon,
|
|
required this.selectedIcon,
|
|
required this.label,
|
|
required this.route,
|
|
});
|
|
}
|