195 lines
7.0 KiB
Dart
195 lines
7.0 KiB
Dart
import 'dart:ui';
|
|
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.
|
|
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;
|
|
|
|
int _statsTick = 0;
|
|
int _historyTick = 0;
|
|
int _homeTick = 0;
|
|
int _garageTick = 0;
|
|
|
|
void selectTab(int index) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
if (index == mainTabHome) _homeTick++;
|
|
if (index == mainTabHistory) _historyTick++;
|
|
if (index == mainTabStats) _statsTick++;
|
|
if (index == mainTabGarage) _garageTick++;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
final screens = [
|
|
HomeScreen(refreshTick: _homeTick),
|
|
HistoryScreen(refreshTick: _historyTick),
|
|
StatisticsScreen(refreshTick: _statsTick),
|
|
WeaponListScreen(refreshTick: _garageTick),
|
|
];
|
|
|
|
return Scaffold(
|
|
extendBody: true,
|
|
body: IndexedStack(
|
|
index: _selectedIndex,
|
|
children: screens,
|
|
),
|
|
bottomNavigationBar: _buildFloatingGlassDock(isDark),
|
|
);
|
|
}
|
|
|
|
Widget _buildFloatingGlassDock(bool isDark) {
|
|
final primaryColor = Theme.of(context).colorScheme.primary;
|
|
final navItems = [
|
|
(Icons.radar_outlined, Icons.radar, 'Accueil'),
|
|
(Icons.history_outlined, Icons.history_rounded, 'Historique'),
|
|
(Icons.insights_outlined, Icons.insights_rounded, 'Stats'),
|
|
(Icons.shield_outlined, Icons.shield, 'Armurerie'),
|
|
];
|
|
|
|
return SafeArea(
|
|
child: Container(
|
|
margin: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
height: 68,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(24),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: isDark ? 0.45 : 0.12),
|
|
blurRadius: 24,
|
|
offset: const Offset(0, 8),
|
|
),
|
|
if (isDark)
|
|
BoxShadow(
|
|
color: primaryColor.withValues(alpha: 0.12),
|
|
blurRadius: 16,
|
|
spreadRadius: -4,
|
|
offset: const Offset(0, -2),
|
|
),
|
|
],
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(24),
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(sigmaX: 16, sigmaY: 16),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: isDark
|
|
? const Color(0xFF101722).withValues(alpha: 0.78)
|
|
: Colors.white.withValues(alpha: 0.85),
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(
|
|
color: isDark
|
|
? Colors.white.withValues(alpha: 0.14)
|
|
: Colors.black.withValues(alpha: 0.08),
|
|
width: 1.2,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: List.generate(navItems.length, (index) {
|
|
final item = navItems[index];
|
|
final isSelected = _selectedIndex == index;
|
|
|
|
return Expanded(
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () => selectTab(index),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
curve: Curves.easeOutCubic,
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? primaryColor.withValues(
|
|
alpha: isDark ? 0.22 : 0.15,
|
|
)
|
|
: Colors.transparent,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: isSelected
|
|
? Border.all(
|
|
color: primaryColor.withValues(
|
|
alpha: isDark ? 0.45 : 0.35,
|
|
),
|
|
width: 1,
|
|
)
|
|
: null,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
isSelected ? item.$2 : item.$1,
|
|
size: 22,
|
|
color: isSelected
|
|
? primaryColor
|
|
: (isDark
|
|
? AppTheme.darkTextSecondary
|
|
: AppTheme.lightTextSecondary),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
item.$3,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: isSelected
|
|
? FontWeight.w700
|
|
: FontWeight.w500,
|
|
color: isSelected
|
|
? primaryColor
|
|
: (isDark
|
|
? AppTheme.darkTextSecondary
|
|
: AppTheme.lightTextSecondary),
|
|
letterSpacing: 0.2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|