fix: filtre par choix de gun, switch sticky

This commit is contained in:
qguillaume
2026-06-20 21:13:26 +02:00
parent a102bfd5ef
commit beb20074f2
2 changed files with 89 additions and 54 deletions

View File

@@ -11,7 +11,12 @@ import '../../services/statistics_service.dart';
class StatisticsScreen extends StatefulWidget {
final Session? singleSession;
const StatisticsScreen({super.key, this.singleSession});
/// Incrémenté par la navigation à chaque fois que l'onglet Stats est ouvert,
/// pour forcer un rechargement des données (l'écran est gardé vivant par un
/// IndexedStack, sinon les filtres arme/distance resteraient périmés).
final int refreshTick;
const StatisticsScreen({super.key, this.singleSession, this.refreshTick = 0});
@override
State<StatisticsScreen> createState() => _StatisticsScreenState();
@@ -44,6 +49,16 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
WidgetsBinding.instance.addPostFrameCallback((_) => _loadStatistics());
}
@override
void didUpdateWidget(StatisticsScreen oldWidget) {
super.didUpdateWidget(oldWidget);
// L'onglet vient d'être ré-ouvert : on recharge pour rafraîchir les listes
// de filtres (armes/distances) et les stats avec les nouvelles sessions.
if (oldWidget.refreshTick != widget.refreshTick) {
_loadStatistics();
}
}
Future<void> _loadStatistics() async {
if (!mounted) return;
setState(() => _isLoading = true);
@@ -217,11 +232,14 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: _loadStatistics,
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(16),
: Column(
children: [
// HEADER COLLANT : filtres + comparateur toujours visibles
Material(
elevation: 2,
color: Theme.of(context).scaffoldBackgroundColor,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
child: Column(
children: [
// 1. FILTRES (Arme et Distance)
@@ -256,12 +274,22 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
),
],
),
const SizedBox(height: 16),
const SizedBox(height: 12),
// 1bis. COMPARATEUR DE SESSIONS
_buildComparator(),
const SizedBox(height: 20),
],
),
),
),
Expanded(
child: RefreshIndicator(
onRefresh: _loadStatistics,
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(16),
child: Column(
children: [
// 2. DONNÉES RAPIDES (Tirs et Sessions)
Row(
children: [
@@ -351,6 +379,9 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
),
),
),
),
],
),
);
}

View File

@@ -15,25 +15,29 @@ class MainNavigationHolder extends StatefulWidget {
class _MainNavigationHolderState extends State<MainNavigationHolder> {
int _selectedIndex = 0;
final List<Widget> _screens = [
const HomeScreen(),
const HistoryScreen(),
const StatisticsScreen(),
const WeaponListScreen(),
];
// Incrémenté à chaque ouverture de l'onglet Stats pour forcer le rechargement
// (l'écran est gardé vivant par l'IndexedStack et ne se rafraîchit pas seul).
int _statsTick = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
if (index == 2) _statsTick++;
});
}
@override
Widget build(BuildContext context) {
final screens = [
const HomeScreen(),
const HistoryScreen(),
StatisticsScreen(refreshTick: _statsTick),
const WeaponListScreen(),
];
return Scaffold(
body: IndexedStack(
index: _selectedIndex,
children: _screens,
children: screens,
),
bottomNavigationBar: Container(
decoration: BoxDecoration(