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 { class StatisticsScreen extends StatefulWidget {
final Session? singleSession; 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 @override
State<StatisticsScreen> createState() => _StatisticsScreenState(); State<StatisticsScreen> createState() => _StatisticsScreenState();
@@ -44,6 +49,16 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
WidgetsBinding.instance.addPostFrameCallback((_) => _loadStatistics()); 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 { Future<void> _loadStatistics() async {
if (!mounted) return; if (!mounted) return;
setState(() => _isLoading = true); setState(() => _isLoading = true);
@@ -217,11 +232,14 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
), ),
body: _isLoading body: _isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: RefreshIndicator( : Column(
onRefresh: _loadStatistics, children: [
child: SingleChildScrollView( // HEADER COLLANT : filtres + comparateur toujours visibles
physics: const AlwaysScrollableScrollPhysics(), Material(
padding: const EdgeInsets.all(16), elevation: 2,
color: Theme.of(context).scaffoldBackgroundColor,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
child: Column( child: Column(
children: [ children: [
// 1. FILTRES (Arme et Distance) // 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 // 1bis. COMPARATEUR DE SESSIONS
_buildComparator(), _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) // 2. DONNÉES RAPIDES (Tirs et Sessions)
Row( Row(
children: [ 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> { class _MainNavigationHolderState extends State<MainNavigationHolder> {
int _selectedIndex = 0; int _selectedIndex = 0;
final List<Widget> _screens = [ // Incrémenté à chaque ouverture de l'onglet Stats pour forcer le rechargement
const HomeScreen(), // (l'écran est gardé vivant par l'IndexedStack et ne se rafraîchit pas seul).
const HistoryScreen(), int _statsTick = 0;
const StatisticsScreen(),
const WeaponListScreen(),
];
void _onItemTapped(int index) { void _onItemTapped(int index) {
setState(() { setState(() {
_selectedIndex = index; _selectedIndex = index;
if (index == 2) _statsTick++;
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screens = [
const HomeScreen(),
const HistoryScreen(),
StatisticsScreen(refreshTick: _statsTick),
const WeaponListScreen(),
];
return Scaffold( return Scaffold(
body: IndexedStack( body: IndexedStack(
index: _selectedIndex, index: _selectedIndex,
children: _screens, children: screens,
), ),
bottomNavigationBar: Container( bottomNavigationBar: Container(
decoration: BoxDecoration( decoration: BoxDecoration(