241 lines
7.7 KiB
Dart
241 lines
7.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../core/services/api_service.dart';
|
|
import '../../core/di/injection.dart';
|
|
import '../../shared/theme/app_theme.dart';
|
|
|
|
/// Page de test pour diagnostiquer les problèmes d'API
|
|
class DebugApiTestPage extends StatefulWidget {
|
|
const DebugApiTestPage({super.key});
|
|
|
|
@override
|
|
State<DebugApiTestPage> createState() => _DebugApiTestPageState();
|
|
}
|
|
|
|
class _DebugApiTestPageState extends State<DebugApiTestPage> {
|
|
final ApiService _apiService = getIt<ApiService>();
|
|
String _result = 'Aucun test effectué';
|
|
bool _isLoading = false;
|
|
|
|
Future<void> _testEvenementsAPI() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
_result = 'Test en cours...';
|
|
});
|
|
|
|
try {
|
|
print('🧪 Début du test API événements');
|
|
final evenements = await _apiService.getEvenementsAVenir();
|
|
|
|
setState(() {
|
|
_result = '''✅ SUCCÈS !
|
|
Nombre d'événements récupérés: ${evenements.length}
|
|
|
|
Détails des événements:
|
|
${evenements.map((e) => '• ${e.titre} (${e.typeEvenement})').join('\n')}
|
|
''';
|
|
_isLoading = false;
|
|
});
|
|
|
|
print('🎉 Test réussi: ${evenements.length} événements');
|
|
} catch (e) {
|
|
setState(() {
|
|
_result = '''❌ ERREUR !
|
|
Type d'erreur: ${e.runtimeType}
|
|
Message: $e
|
|
|
|
Vérifiez:
|
|
1. Le serveur backend est-il démarré ?
|
|
2. L'URL est-elle correcte ?
|
|
3. Le réseau est-il accessible ?
|
|
''';
|
|
_isLoading = false;
|
|
});
|
|
|
|
print('💥 Test échoué: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> _testConnectivity() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
_result = 'Test de connectivité...';
|
|
});
|
|
|
|
try {
|
|
// Test simple de connectivité via l'API service
|
|
final evenements = await _apiService.getEvenementsAVenir(size: 1);
|
|
|
|
setState(() {
|
|
_result = '''✅ CONNECTIVITÉ OK !
|
|
Connexion au serveur réussie.
|
|
Nombre d'événements de test: ${evenements.length}
|
|
''';
|
|
_isLoading = false;
|
|
});
|
|
} catch (e) {
|
|
setState(() {
|
|
_result = '''❌ PROBLÈME DE CONNECTIVITÉ !
|
|
Erreur: $e
|
|
|
|
Le serveur backend n'est pas accessible.
|
|
Vérifiez que le serveur Quarkus est démarré sur 192.168.1.145:8080
|
|
''';
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Debug API Test'),
|
|
backgroundColor: AppTheme.primaryColor,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Tests de Diagnostic',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
ElevatedButton.icon(
|
|
onPressed: _isLoading ? null : _testConnectivity,
|
|
icon: const Icon(Icons.network_check),
|
|
label: const Text('Test Connectivité'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppTheme.primaryColor,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
ElevatedButton.icon(
|
|
onPressed: _isLoading ? null : _testEvenementsAPI,
|
|
icon: const Icon(Icons.event),
|
|
label: const Text('Test API Événements'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppTheme.successColor,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Expanded(
|
|
child: Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
const Text(
|
|
'Résultats',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
if (_isLoading)
|
|
const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Expanded(
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: Colors.grey[300]!),
|
|
),
|
|
child: SingleChildScrollView(
|
|
child: Text(
|
|
_result,
|
|
style: const TextStyle(
|
|
fontFamily: 'monospace',
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Card(
|
|
color: Colors.blue[50],
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(Icons.info, color: Colors.blue[700]),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'Informations de Configuration',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.blue[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
const Text(
|
|
'URL Backend: http://192.168.1.145:8080\n'
|
|
'Endpoint: /api/evenements/a-venir-public\n'
|
|
'Méthode: GET',
|
|
style: TextStyle(
|
|
fontFamily: 'monospace',
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|