feat: accessoires en armurerie, comparateur de sessions stats, croix de centrage pixel par pixel
This commit is contained in:
@@ -30,6 +30,14 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
|
||||
List<String> _availableWeapons = ['Toutes'];
|
||||
List<String> _availableDistances = ['Toutes'];
|
||||
|
||||
// --- Comparateur de sessions ---
|
||||
// Quand 2 sessions sont sélectionnées, l'écran passe en mode comparaison :
|
||||
// un switch permet d'alterner l'affichage des stats entre la session A et B.
|
||||
Session? _compareA;
|
||||
Session? _compareB;
|
||||
bool _showingB = false; // false = on affiche A, true = on affiche B
|
||||
bool get _compareMode => _compareA != null && _compareB != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -80,6 +88,17 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
|
||||
}
|
||||
|
||||
void _calculateStats() {
|
||||
// Mode comparaison : on calcule les stats sur la seule session active
|
||||
// (A ou B selon le switch), sans filtre de période.
|
||||
if (_compareMode) {
|
||||
final active = _showingB ? _compareB! : _compareA!;
|
||||
_statistics = _statisticsService.calculateStatistics(
|
||||
[active],
|
||||
period: StatsPeriod.all,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Filtrer les sessions avant calcul
|
||||
final filteredSessions = _allSessions.where((s) {
|
||||
final weaponMatch = _selectedWeapon == 'Toutes' || s.weapon == _selectedWeapon;
|
||||
@@ -93,6 +112,80 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String _sessionLabel(Session s) {
|
||||
final d = s.createdAt;
|
||||
final date = '${d.day.toString().padLeft(2, '0')}/${d.month.toString().padLeft(2, '0')}/${d.year}';
|
||||
return '${s.weapon} • $date • ${s.totalScore} pts';
|
||||
}
|
||||
|
||||
// Sélection des 2 sessions à comparer via un dialog à deux listes déroulantes.
|
||||
Future<void> _openCompareDialog() async {
|
||||
if (_allSessions.length < 2) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Il faut au moins 2 sessions enregistrées pour comparer.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Session? a = _compareA ?? _allSessions[0];
|
||||
Session? b = _compareB ?? _allSessions[1];
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setState) => AlertDialog(
|
||||
title: const Text('Comparer 2 sessions'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DropdownButtonFormField<Session>(
|
||||
initialValue: a,
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(labelText: 'Session A'),
|
||||
items: _allSessions
|
||||
.map((s) => DropdownMenuItem(value: s, child: Text(_sessionLabel(s), overflow: TextOverflow.ellipsis)))
|
||||
.toList(),
|
||||
onChanged: (v) => setState(() => a = v),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<Session>(
|
||||
initialValue: b,
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(labelText: 'Session B'),
|
||||
items: _allSessions
|
||||
.map((s) => DropdownMenuItem(value: s, child: Text(_sessionLabel(s), overflow: TextOverflow.ellipsis)))
|
||||
.toList(),
|
||||
onChanged: (v) => setState(() => b = v),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('Annuler')),
|
||||
ElevatedButton(onPressed: () => Navigator.pop(context, true), child: const Text('Comparer')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && a != null && b != null) {
|
||||
setState(() {
|
||||
_compareA = a;
|
||||
_compareB = b;
|
||||
_showingB = false;
|
||||
_calculateStats();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _exitCompareMode() {
|
||||
setState(() {
|
||||
_compareA = null;
|
||||
_compareB = null;
|
||||
_showingB = false;
|
||||
_calculateStats();
|
||||
});
|
||||
}
|
||||
|
||||
List<double> _getScoreHistory() {
|
||||
if (_statistics == null || _statistics!.sessions.isEmpty) return [0];
|
||||
// Sort sessions by date and take last 10
|
||||
@@ -163,6 +256,10 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 1bis. COMPARATEUR DE SESSIONS
|
||||
_buildComparator(),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 2. DONNÉES RAPIDES (Tirs et Sessions)
|
||||
@@ -257,9 +354,97 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// Comparateur : bouton pour choisir 2 sessions, puis switch pour alterner.
|
||||
Widget _buildComparator() {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (!_compareMode) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _openCompareDialog,
|
||||
icon: const Icon(Icons.compare_arrows),
|
||||
label: const Text('Comparer 2 sessions'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final activeColor = const Color(0xFF1A73E8);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: activeColor.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: activeColor.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.compare_arrows, color: activeColor, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text('Comparaison', style: TextStyle(fontWeight: FontWeight.bold, color: activeColor)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
tooltip: 'Quitter la comparaison',
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
onPressed: _exitCompareMode,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Switch pour alterner entre les 2 sessions.
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'A · ${_sessionLabel(_compareA!)}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _showingB ? theme.textTheme.bodySmall?.color?.withValues(alpha: 0.5) : null,
|
||||
fontWeight: _showingB ? FontWeight.normal : FontWeight.bold,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Switch(
|
||||
value: _showingB,
|
||||
activeThumbColor: activeColor,
|
||||
onChanged: (v) => setState(() {
|
||||
_showingB = v;
|
||||
_calculateStats();
|
||||
}),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'B · ${_sessionLabel(_compareB!)}',
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _showingB ? null : theme.textTheme.bodySmall?.color?.withValues(alpha: 0.5),
|
||||
fontWeight: _showingB ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Affichage : session ${_showingB ? 'B' : 'A'}',
|
||||
style: TextStyle(fontSize: 11, color: theme.textTheme.bodySmall?.color?.withValues(alpha: 0.6)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdown(
|
||||
String label,
|
||||
String value,
|
||||
String label,
|
||||
String value,
|
||||
List<String> items,
|
||||
void Function(String?) onChanged,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user