refactor: perf getAllSessions, zéro warning analyze, docs à jour
- getAllSessions : élimine le N+1 (une requête par session + par analyse) au profit de 3 requêtes groupées (sessions, analyses IN, shots IN), découpées en paquets de 500 pour rester sous la limite SQLite. Assemblage en mémoire via maps — accueil/historique/stats ne ralentiront plus au fil des mois - flutter analyze : 28 -> 0 problème. APIs dépréciées migrées (withOpacity -> withValues, scale -> scaleByDouble, DropdownButtonFormField.value -> initialValue, dialogBackgroundColor -> dialogTheme, activeColor -> activeThumbColor), use_build_context_synchronously corrigés dans l'armurerie (repository capturé avant await + gardes mounted), print -> debugPrint, identifiants TopLeft/... -> lowerCamelCase, blocs if, champ final - _showShotDetails dédupliqué : bottom sheet extraite dans le widget partagé shot_details_sheet.dart, utilisée par l'écran d'analyse et l'éditeur d'impacts - CLAUDE.md : sections Features réécrites (retrait détection auto/références, ajout capture/plotting manuel) ; description pubspec renseignée Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,7 +52,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () => _showEditWeaponDialog(context),
|
||||
onPressed: _showEditWeaponDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -74,7 +74,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => _showAddMaintenanceDialog(context),
|
||||
onPressed: _showAddMaintenanceDialog,
|
||||
label: const Text('Entretien'),
|
||||
icon: const Icon(Icons.build),
|
||||
),
|
||||
@@ -166,7 +166,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
padding: const EdgeInsets.all(8),
|
||||
minimumSize: const Size(36, 36),
|
||||
),
|
||||
onPressed: () => _showEditAccessoriesDialog(context),
|
||||
onPressed: _showEditAccessoriesDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -223,7 +223,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
title: Text(entry.type.displayName),
|
||||
subtitle: Text(entry.description),
|
||||
trailing: Text(DateFormat('dd/MM/yy').format(entry.date), style: const TextStyle(fontSize: 12)),
|
||||
onLongPress: () => _confirmDeleteMaintenance(context, entry),
|
||||
onLongPress: () => _confirmDeleteMaintenance(entry),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -279,7 +279,9 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showEditWeaponDialog(BuildContext context) async {
|
||||
void _showEditWeaponDialog() async {
|
||||
// Capturé AVANT l'await : plus aucun usage du context après le dialogue.
|
||||
final repository = context.read<SessionRepository>();
|
||||
final nameController = TextEditingController(text: _weapon.name);
|
||||
final caliberController = TextEditingController(text: _weapon.caliber);
|
||||
final magCountController = TextEditingController(text: _weapon.magazineCount.toString());
|
||||
@@ -309,7 +311,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
decoration: const InputDecoration(labelText: 'Surnom / Custom Name', hintText: 'ex: Mon Glock de Compète'),
|
||||
)),
|
||||
DropdownButtonFormField<WeaponType>(
|
||||
value: selectedType,
|
||||
initialValue: selectedType,
|
||||
decoration: const InputDecoration(labelText: 'Type'),
|
||||
items: WeaponType.values.map((t) => DropdownMenuItem(value: t, child: Text(t.displayName))).toList(),
|
||||
onChanged: (v) => setState(() => selectedType = v!),
|
||||
@@ -382,9 +384,9 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
trigger: triggerController.text.isEmpty ? null : triggerController.text,
|
||||
customName: customNameController.text.isEmpty ? null : customNameController.text,
|
||||
);
|
||||
|
||||
final repository = context.read<SessionRepository>();
|
||||
|
||||
await repository.updateWeapon(updatedWeapon);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_weapon = updatedWeapon;
|
||||
});
|
||||
@@ -395,7 +397,9 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
// fortement des accessoires, on ne modifie PAS l'arme existante : on crée une
|
||||
// nouvelle arme (même modèle, accessoires différents) dans l'armurerie afin de
|
||||
// pouvoir comparer les scores selon la configuration utilisée.
|
||||
void _showEditAccessoriesDialog(BuildContext context) async {
|
||||
void _showEditAccessoriesDialog() async {
|
||||
// Capturé AVANT l'await : plus aucun usage du context après le dialogue.
|
||||
final repository = context.read<SessionRepository>();
|
||||
final opticController = TextEditingController(text: _weapon.optic);
|
||||
final silencerController = TextEditingController(text: _weapon.silencer);
|
||||
final triggerController = TextEditingController(text: _weapon.trigger);
|
||||
@@ -444,7 +448,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
),
|
||||
);
|
||||
|
||||
if (result != true) return;
|
||||
if (result != true || !mounted) return;
|
||||
|
||||
final newOptic = opticController.text.isEmpty ? null : opticController.text;
|
||||
final newSilencer = silencerController.text.isEmpty ? null : silencerController.text;
|
||||
@@ -456,11 +460,9 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
newSilencer == _weapon.silencer &&
|
||||
newTrigger == _weapon.trigger;
|
||||
if (unchanged) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Aucun accessoire modifié, aucune configuration créée.')),
|
||||
);
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Aucun accessoire modifié, aucune configuration créée.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -472,7 +474,6 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
newCustomName = accessories.isEmpty ? null : '${_weapon.name} ($accessories)';
|
||||
}
|
||||
|
||||
final repository = context.read<SessionRepository>();
|
||||
final newWeapon = await repository.addWeapon(
|
||||
name: _weapon.name,
|
||||
type: _weapon.type,
|
||||
@@ -497,7 +498,9 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddMaintenanceDialog(BuildContext context) async {
|
||||
void _showAddMaintenanceDialog() async {
|
||||
// Capturé AVANT l'await : plus aucun usage du context après le dialogue.
|
||||
final repository = context.read<SessionRepository>();
|
||||
final descController = TextEditingController();
|
||||
MaintenanceType selectedType = MaintenanceType.cleaning;
|
||||
DateTime selectedDate = DateTime.now();
|
||||
@@ -511,7 +514,7 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DropdownButtonFormField<MaintenanceType>(
|
||||
value: selectedType,
|
||||
initialValue: selectedType,
|
||||
decoration: const InputDecoration(labelText: 'Type d\'intervention'),
|
||||
items: MaintenanceType.values.map((t) => DropdownMenuItem(value: t, child: Text(t.displayName))).toList(),
|
||||
onChanged: (v) => setState(() => selectedType = v!),
|
||||
@@ -553,7 +556,6 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
);
|
||||
|
||||
if (result == true && descController.text.isNotEmpty) {
|
||||
final repository = context.read<SessionRepository>();
|
||||
await repository.addMaintenanceEntry(
|
||||
weaponId: _weapon.id,
|
||||
type: selectedType,
|
||||
@@ -561,11 +563,14 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
roundsSinceLast: _totalRounds,
|
||||
date: selectedDate,
|
||||
);
|
||||
if (!mounted) return;
|
||||
_loadData();
|
||||
}
|
||||
}
|
||||
|
||||
void _confirmDeleteMaintenance(BuildContext context, MaintenanceEntry entry) async {
|
||||
void _confirmDeleteMaintenance(MaintenanceEntry entry) async {
|
||||
// Capturé AVANT l'await : plus aucun usage du context après le dialogue.
|
||||
final repository = context.read<SessionRepository>();
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
@@ -582,8 +587,8 @@ class _WeaponDetailScreenState extends State<WeaponDetailScreen> {
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
final repository = context.read<SessionRepository>();
|
||||
await repository.deleteMaintenanceEntry(entry.id);
|
||||
if (!mounted) return;
|
||||
_loadData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user