68 lines
2.2 KiB
Dart
68 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
|
import 'package:geosector_app/core/services/app_info_service.dart';
|
|
import 'package:geosector_app/core/services/api_service.dart';
|
|
import 'package:geosector_app/app.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
void main() async {
|
|
// IMPORTANT: Configurer l'URL strategy pour éviter les # dans les URLs
|
|
usePathUrlStrategy();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Initialiser les services essentiels
|
|
await _initializeServices();
|
|
|
|
// Initialiser Hive de façon minimale (le traitement lourd se fait dans splash)
|
|
await _initializeHive();
|
|
|
|
// Configurer l'orientation de l'application (mobile uniquement)
|
|
if (!kIsWeb) {
|
|
await SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.portraitUp,
|
|
DeviceOrientation.portraitDown,
|
|
]);
|
|
}
|
|
|
|
// Lancer l'application
|
|
runApp(const GeosectorApp());
|
|
}
|
|
|
|
/// Initialise les services essentiels
|
|
Future<void> _initializeServices() async {
|
|
try {
|
|
// Initialiser ApiService en premier
|
|
await ApiService.initialize();
|
|
debugPrint('✅ ApiService singleton initialisé');
|
|
|
|
// Les services CurrentUserService et CurrentAmicaleService s'initialisent automatiquement
|
|
// au premier accès via le pattern singleton lazy
|
|
debugPrint('✅ CurrentUserService prêt');
|
|
debugPrint('✅ CurrentAmicaleService prêt');
|
|
|
|
await AppInfoService.initialize();
|
|
debugPrint('✅ Tous les services initialisés avec succès');
|
|
} catch (e) {
|
|
debugPrint('❌ Erreur lors de l\'initialisation des services: $e');
|
|
rethrow; // Important pour arrêter l'app si les services critiques échouent
|
|
}
|
|
}
|
|
|
|
/// Initialise Hive de façon minimale (le traitement lourd se fait dans splash_page)
|
|
Future<void> _initializeHive() async {
|
|
try {
|
|
debugPrint('🔧 Initialisation minimale de Hive...');
|
|
|
|
// SEULEMENT l'initialisation de base - pas d'adaptateurs, pas de Box
|
|
await Hive.initFlutter();
|
|
|
|
debugPrint('✅ Hive initialisé (traitement lourd dans splash_page)');
|
|
} catch (e) {
|
|
debugPrint('❌ Erreur Hive: $e');
|
|
rethrow;
|
|
}
|
|
}
|