feat: synchronisation mode deconnecte fin chat et stats
This commit is contained in:
@@ -16,10 +16,8 @@ import 'package:geosector_app/presentation/dialogs/sector_dialog.dart';
|
||||
import 'package:geosector_app/core/repositories/sector_repository.dart';
|
||||
import 'package:geosector_app/core/repositories/passage_repository.dart';
|
||||
import 'package:geosector_app/core/services/current_amicale_service.dart';
|
||||
import 'package:geosector_app/core/services/api_service.dart';
|
||||
import 'package:geosector_app/core/services/current_user_service.dart';
|
||||
import 'package:geosector_app/core/repositories/operation_repository.dart';
|
||||
import 'package:geosector_app/core/services/data_loading_service.dart';
|
||||
import 'package:geosector_app/presentation/widgets/passage_map_dialog.dart';
|
||||
|
||||
class AdminMapPage extends StatefulWidget {
|
||||
@@ -98,7 +96,7 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
_loadPassages();
|
||||
|
||||
// Écouter les changements du secteur sélectionné
|
||||
_settingsListenable = _settingsBox.listenable(keys: ['admin_selectedSectorId']);
|
||||
_settingsListenable = _settingsBox.listenable(keys: ['selectedSectorId']);
|
||||
_settingsListenable.addListener(_onSectorSelectionChanged);
|
||||
|
||||
// Centrer la carte une seule fois après le chargement initial
|
||||
@@ -122,12 +120,12 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
}
|
||||
|
||||
// Charger le secteur sélectionné
|
||||
_selectedSectorId = _settingsBox.get('admin_selectedSectorId');
|
||||
_selectedSectorId = _settingsBox.get('selectedSectorId');
|
||||
|
||||
// Charger la position et le zoom
|
||||
final double? savedLat = _settingsBox.get('admin_mapLat');
|
||||
final double? savedLng = _settingsBox.get('admin_mapLng');
|
||||
final double? savedZoom = _settingsBox.get('admin_mapZoom');
|
||||
final double? savedLat = _settingsBox.get('mapLat');
|
||||
final double? savedLng = _settingsBox.get('mapLng');
|
||||
final double? savedZoom = _settingsBox.get('mapZoom');
|
||||
|
||||
if (savedLat != null && savedLng != null) {
|
||||
_currentPosition = LatLng(savedLat, savedLng);
|
||||
@@ -140,7 +138,7 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
|
||||
// Méthode pour gérer les changements de sélection de secteur
|
||||
void _onSectorSelectionChanged() {
|
||||
final newSectorId = _settingsBox.get('admin_selectedSectorId');
|
||||
final newSectorId = _settingsBox.get('selectedSectorId');
|
||||
if (newSectorId != null && newSectorId != _selectedSectorId) {
|
||||
setState(() {
|
||||
_selectedSectorId = newSectorId;
|
||||
@@ -169,13 +167,13 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
void _saveSettings() {
|
||||
// Sauvegarder le secteur sélectionné
|
||||
if (_selectedSectorId != null) {
|
||||
_settingsBox.put('admin_selectedSectorId', _selectedSectorId);
|
||||
_settingsBox.put('selectedSectorId', _selectedSectorId);
|
||||
}
|
||||
|
||||
// Sauvegarder la position et le zoom actuels
|
||||
_settingsBox.put('admin_mapLat', _currentPosition.latitude);
|
||||
_settingsBox.put('admin_mapLng', _currentPosition.longitude);
|
||||
_settingsBox.put('admin_mapZoom', _currentZoom);
|
||||
_settingsBox.put('mapLat', _currentPosition.latitude);
|
||||
_settingsBox.put('mapLng', _currentPosition.longitude);
|
||||
_settingsBox.put('mapZoom', _currentZoom);
|
||||
}
|
||||
|
||||
// Charger les secteurs depuis la boîte (pour ValueListenableBuilder)
|
||||
@@ -622,8 +620,8 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
_updateMapPosition(position, zoom: 17);
|
||||
|
||||
// Sauvegarder la nouvelle position
|
||||
_settingsBox.put('admin_mapLat', position.latitude);
|
||||
_settingsBox.put('admin_mapLng', position.longitude);
|
||||
_settingsBox.put('mapLat', position.latitude);
|
||||
_settingsBox.put('mapLng', position.longitude);
|
||||
|
||||
// Informer l'utilisateur
|
||||
if (mounted) {
|
||||
@@ -2776,7 +2774,9 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
final sectorRepository = SectorRepository();
|
||||
final result = await sectorRepository.deleteSectorFromApi(_sectorToDeleteId!);
|
||||
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
}
|
||||
|
||||
if (result['status'] == 'success') {
|
||||
// Si le secteur supprimé était sélectionné, réinitialiser la sélection
|
||||
@@ -2805,21 +2805,25 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
}
|
||||
} else {
|
||||
final errorMessage = result['message'] ?? 'Erreur lors de la suppression du secteur';
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(errorMessage),
|
||||
content: Text('Erreur: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
setState(() {
|
||||
_mapMode = MapMode.view;
|
||||
@@ -2863,7 +2867,8 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
|
||||
try {
|
||||
// Afficher un indicateur de chargement
|
||||
ScaffoldMessenger.of(parentContext).showSnackBar(
|
||||
if (parentContext.mounted) {
|
||||
ScaffoldMessenger.of(parentContext).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
@@ -2879,6 +2884,7 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
duration: Duration(seconds: 30),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final sectorRepository = SectorRepository();
|
||||
int passagesCreated = 0;
|
||||
@@ -2960,10 +2966,12 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
});
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(parentContext).hideCurrentSnackBar();
|
||||
if (parentContext.mounted) {
|
||||
ScaffoldMessenger.of(parentContext).hideCurrentSnackBar();
|
||||
}
|
||||
|
||||
// Message de succès simple pour la création
|
||||
if (mounted) {
|
||||
if (mounted && parentContext.mounted) {
|
||||
String message = 'Secteur "$name" créé avec succès. ';
|
||||
if (passagesCreated > 0) {
|
||||
message += '$passagesCreated passages créés.';
|
||||
@@ -3012,10 +3020,12 @@ class _AdminMapPageState extends State<AdminMapPage> {
|
||||
_loadSectors();
|
||||
_loadPassages();
|
||||
|
||||
ScaffoldMessenger.of(parentContext).hideCurrentSnackBar();
|
||||
if (parentContext.mounted) {
|
||||
ScaffoldMessenger.of(parentContext).hideCurrentSnackBar();
|
||||
}
|
||||
|
||||
// Message de succès simple pour la modification
|
||||
if (mounted) {
|
||||
if (mounted && parentContext.mounted) {
|
||||
String message = 'Secteur "$name" modifié avec succès. ';
|
||||
final passagesUpdated = result['passages_updated'] ?? 0;
|
||||
final passagesCreated = result['passages_created'] ?? 0;
|
||||
|
||||
Reference in New Issue
Block a user