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,51 +232,64 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: _loadStatistics,
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(16),
child: Column(
children: [
// 1. FILTRES (Arme et Distance)
Row(
children: [
Expanded(
child: _buildDropdown(
'Arme utilisée',
_selectedWeapon,
_availableWeapons,
(val) {
setState(() {
_selectedWeapon = val!;
_calculateStats();
});
},
: 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)
Row(
children: [
Expanded(
child: _buildDropdown(
'Arme utilisée',
_selectedWeapon,
_availableWeapons,
(val) {
setState(() {
_selectedWeapon = val!;
_calculateStats();
});
},
),
),
const SizedBox(width: 12),
Expanded(
child: _buildDropdown(
'Distance',
_selectedDistance,
_availableDistances,
(val) {
setState(() {
_selectedDistance = val!;
_calculateStats();
});
},
),
),
],
),
),
const SizedBox(width: 12),
Expanded(
child: _buildDropdown(
'Distance',
_selectedDistance,
_availableDistances,
(val) {
setState(() {
_selectedDistance = val!;
_calculateStats();
});
},
),
),
],
const SizedBox(height: 12),
// 1bis. COMPARATEUR DE SESSIONS
_buildComparator(),
],
),
),
const SizedBox(height: 16),
// 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: [
@@ -347,10 +375,13 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
],
const SizedBox(height: 30),
],
),
],
),
),
),
),
],
),
),
);
}