108 lines
3.3 KiB
Dart
108 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'features/home/home_screen.dart';
|
|
import 'features/history/history_screen.dart';
|
|
import 'features/statistics/statistics_screen.dart';
|
|
import 'features/garage/weapon_list_screen.dart';
|
|
import 'core/theme/app_theme.dart';
|
|
|
|
/// Index des onglets de la barre de navigation principale.
|
|
const int mainTabHome = 0;
|
|
const int mainTabHistory = 1;
|
|
const int mainTabStats = 2;
|
|
const int mainTabGarage = 3;
|
|
|
|
/// Clé du holder : permet de piloter l'onglet actif depuis n'importe quel
|
|
/// écran (ex. fin de session -> onglet Stats).
|
|
final GlobalKey<State<MainNavigationHolder>> mainNavKey =
|
|
GlobalKey<State<MainNavigationHolder>>();
|
|
|
|
/// Ouvre l'onglet [index] de la navigation principale.
|
|
void openMainTab(int index) {
|
|
final state = mainNavKey.currentState;
|
|
if (state is _MainNavigationHolderState) state.selectTab(index);
|
|
}
|
|
|
|
class MainNavigationHolder extends StatefulWidget {
|
|
const MainNavigationHolder({super.key});
|
|
|
|
@override
|
|
State<MainNavigationHolder> createState() => _MainNavigationHolderState();
|
|
}
|
|
|
|
class _MainNavigationHolderState extends State<MainNavigationHolder> {
|
|
int _selectedIndex = 0;
|
|
|
|
// Incrémentés à chaque ouverture de l'onglet correspondant pour forcer le
|
|
// rechargement (les écrans sont gardés vivants par l'IndexedStack et ne se
|
|
// rafraîchissent pas seuls).
|
|
int _statsTick = 0;
|
|
int _historyTick = 0;
|
|
|
|
void selectTab(int index) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
if (index == mainTabHistory) _historyTick++;
|
|
if (index == mainTabStats) _statsTick++;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final screens = [
|
|
const HomeScreen(),
|
|
HistoryScreen(refreshTick: _historyTick),
|
|
StatisticsScreen(refreshTick: _statsTick),
|
|
const WeaponListScreen(),
|
|
];
|
|
return Scaffold(
|
|
body: IndexedStack(
|
|
index: _selectedIndex,
|
|
children: screens,
|
|
),
|
|
bottomNavigationBar: Container(
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.1),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, -2),
|
|
),
|
|
],
|
|
),
|
|
child: BottomNavigationBar(
|
|
currentIndex: _selectedIndex,
|
|
onTap: selectTab,
|
|
type: BottomNavigationBarType.fixed,
|
|
backgroundColor: Theme.of(context).cardColor,
|
|
selectedItemColor: AppTheme.primaryColor,
|
|
unselectedItemColor: Colors.grey,
|
|
showUnselectedLabels: true,
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home_outlined),
|
|
activeIcon: Icon(Icons.home),
|
|
label: 'Accueil',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.history_outlined),
|
|
activeIcon: Icon(Icons.history),
|
|
label: 'Historique',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.analytics_outlined),
|
|
activeIcon: Icon(Icons.analytics),
|
|
label: 'Stats',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.shield_outlined),
|
|
activeIcon: Icon(Icons.shield),
|
|
label: 'Armurerie',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|