You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.5 KiB
134 lines
4.5 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:youmazgestion/Services/stock_managementDatabase.dart';
|
|
import 'package:youmazgestion/controller/userController.dart';
|
|
import 'my_app.dart';
|
|
import 'package:logging/logging.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
try {
|
|
// print("Initialisation de l'application...");
|
|
|
|
// // Pour le développement : supprimer toutes les tables (équivalent à deleteDatabaseFile)
|
|
// // ATTENTION: Décommentez seulement si vous voulez réinitialiser la base
|
|
// // await AppDatabase.instance.deleteDatabaseFile();
|
|
|
|
// // Initialiser la base de données MySQL
|
|
// print("Connexion à la base de données MySQL...");
|
|
// // await AppDatabase.instance.initDatabase();
|
|
// print("Base de données initialisée avec succès !");
|
|
|
|
// Afficher les informations de la base (pour debug)
|
|
await AppDatabase.instance.printDatabaseInfo();
|
|
|
|
// Initialiser le contrôleur utilisateur
|
|
Get.put(UserController());
|
|
// print("Contrôleur utilisateur initialisé");
|
|
|
|
// Configurer le logger
|
|
setupLogger();
|
|
|
|
// print("Lancement de l'application...");
|
|
runApp(const GetMaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: MyApp(),
|
|
));
|
|
} catch (e) {
|
|
// print('Erreur lors de l\'initialisation: $e');
|
|
|
|
// Afficher une page d'erreur avec plus de détails
|
|
runApp(MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: Scaffold(
|
|
backgroundColor: Colors.red[50],
|
|
appBar: AppBar(
|
|
title: const Text('Erreur d\'initialisation'),
|
|
backgroundColor: Colors.red,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Icon(
|
|
Icons.error,
|
|
color: Colors.red,
|
|
size: 48,
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Erreur de connexion à la base de données',
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.red,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Vérifiez que :',
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text('• XAMPP est démarré'),
|
|
const Text('• MySQL est en cours d\'exécution'),
|
|
const Text('• La base de données "guycom_databse" existe'),
|
|
const Text('• Les paramètres de connexion sont corrects'),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Détails de l\'erreur :',
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Expanded(
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[200],
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: Colors.grey),
|
|
),
|
|
child: SingleChildScrollView(
|
|
child: Text(
|
|
e.toString(),
|
|
style: const TextStyle(
|
|
fontFamily: 'monospace',
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: () {
|
|
// Relancer l'application
|
|
main();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
child: const Text('Réessayer'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
));
|
|
}
|
|
}
|
|
|
|
void setupLogger() {
|
|
Logger.root.level = Level.ALL;
|
|
Logger.root.onRecord.listen((record) {
|
|
// print('${record.level.name}: ${record.time}: ${record.message}');
|
|
});
|
|
}
|
|
|