feat(mobile): Implement Keycloak WebView authentication with HTTP callback

- Replace flutter_appauth with custom WebView implementation to resolve deep link issues
- Add KeycloakWebViewAuthService with integrated WebView for seamless authentication
- Configure Android manifest for HTTP cleartext traffic support
- Add network security config for development environment (192.168.1.11)
- Update Keycloak client to use HTTP callback endpoint (http://192.168.1.11:8080/auth/callback)
- Remove obsolete keycloak_auth_service.dart and temporary scripts
- Clean up dependencies and regenerate injection configuration
- Tested successfully on multiple Android devices (Xiaomi 2201116TG, SM A725F)

BREAKING CHANGE: Authentication flow now uses WebView instead of external browser
- Users will see Keycloak login page within the app instead of browser redirect
- Resolves ERR_CLEARTEXT_NOT_PERMITTED and deep link state management issues
- Maintains full OIDC compliance with PKCE flow and secure token storage

Technical improvements:
- WebView with custom navigation delegate for callback handling
- Automatic token extraction and user info parsing from JWT
- Proper error handling and user feedback
- Consistent authentication state management across app lifecycle
This commit is contained in:
DahoudG
2025-09-15 01:44:16 +00:00
parent 73459b3092
commit f89f6167cc
290 changed files with 34563 additions and 3528 deletions

View File

@@ -0,0 +1,682 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../core/di/injection.dart';
import '../../../../core/models/evenement_model.dart';
import '../../../../shared/theme/app_theme.dart';
import '../../../../shared/widgets/buttons/buttons.dart';
import '../bloc/evenement_bloc.dart';
import '../bloc/evenement_event.dart';
import '../bloc/evenement_state.dart';
/// Page de création d'un nouvel événement
class EvenementCreatePage extends StatefulWidget {
const EvenementCreatePage({super.key});
@override
State<EvenementCreatePage> createState() => _EvenementCreatePageState();
}
class _EvenementCreatePageState extends State<EvenementCreatePage> {
final _formKey = GlobalKey<FormState>();
final _scrollController = ScrollController();
// Controllers pour les champs de texte
final _titreController = TextEditingController();
final _descriptionController = TextEditingController();
final _lieuController = TextEditingController();
final _adresseController = TextEditingController();
final _capaciteMaxController = TextEditingController();
final _prixController = TextEditingController();
final _notesController = TextEditingController();
// Variables pour les sélections
DateTime? _dateDebut;
DateTime? _dateFin;
TimeOfDay? _heureDebut;
TimeOfDay? _heureFin;
TypeEvenement _typeSelectionne = TypeEvenement.reunion;
bool _visiblePublic = true;
bool _inscriptionRequise = true;
bool _inscriptionPayante = false;
late EvenementBloc _evenementBloc;
@override
void initState() {
super.initState();
_evenementBloc = getIt<EvenementBloc>();
}
@override
void dispose() {
_titreController.dispose();
_descriptionController.dispose();
_lieuController.dispose();
_adresseController.dispose();
_capaciteMaxController.dispose();
_prixController.dispose();
_notesController.dispose();
_scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocProvider.value(
value: _evenementBloc,
child: Scaffold(
backgroundColor: AppTheme.backgroundLight,
appBar: AppBar(
title: const Text('Nouvel Événement'),
backgroundColor: AppTheme.primaryColor,
foregroundColor: Colors.white,
elevation: 0,
actions: [
BlocBuilder<EvenementBloc, EvenementState>(
builder: (context, state) {
return TextButton(
onPressed: state is EvenementLoading ? null : _sauvegarder,
child: state is EvenementLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: const Text(
'Créer',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
);
},
),
],
),
body: BlocListener<EvenementBloc, EvenementState>(
listener: (context, state) {
if (state is EvenementOperationSuccess) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Événement créé avec succès !'),
backgroundColor: AppTheme.successColor,
),
);
Navigator.of(context).pop(true); // Retourner true pour indiquer la création
} else if (state is EvenementError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Erreur : ${state.message}'),
backgroundColor: AppTheme.errorColor,
),
);
}
},
child: Form(
key: _formKey,
child: SingleChildScrollView(
controller: _scrollController,
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildInformationsGenerales(),
const SizedBox(height: 24),
_buildDateEtHeure(),
const SizedBox(height: 24),
_buildLieuEtAdresse(),
const SizedBox(height: 24),
_buildParametres(),
const SizedBox(height: 24),
_buildInformationsComplementaires(),
const SizedBox(height: 32),
],
),
),
),
),
),
);
}
Widget _buildInformationsGenerales() {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Informations générales',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 16),
TextFormField(
controller: _titreController,
decoration: const InputDecoration(
labelText: 'Titre de l\'événement *',
hintText: 'Ex: Assemblée générale 2025',
prefixIcon: Icon(Icons.title),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Le titre est obligatoire';
}
if (value.trim().length < 3) {
return 'Le titre doit contenir au moins 3 caractères';
}
return null;
},
textCapitalization: TextCapitalization.words,
),
const SizedBox(height: 16),
DropdownButtonFormField<TypeEvenement>(
value: _typeSelectionne,
decoration: const InputDecoration(
labelText: 'Type d\'événement *',
prefixIcon: Icon(Icons.category),
),
items: TypeEvenement.values.map((type) {
return DropdownMenuItem(
value: type,
child: Row(
children: [
Text(type.icone, style: const TextStyle(fontSize: 20)),
const SizedBox(width: 8),
Text(type.libelle),
],
),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_typeSelectionne = value;
});
}
},
),
const SizedBox(height: 16),
TextFormField(
controller: _descriptionController,
decoration: const InputDecoration(
labelText: 'Description',
hintText: 'Décrivez votre événement...',
prefixIcon: Icon(Icons.description),
),
maxLines: 4,
textCapitalization: TextCapitalization.sentences,
),
],
),
),
);
}
Widget _buildDateEtHeure() {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Date et heure',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: InkWell(
onTap: _selectionnerDateDebut,
child: InputDecorator(
decoration: const InputDecoration(
labelText: 'Date de début *',
prefixIcon: Icon(Icons.calendar_today),
),
child: Text(
_dateDebut != null
? DateFormat('dd/MM/yyyy').format(_dateDebut!)
: 'Sélectionner',
style: TextStyle(
color: _dateDebut != null ? null : Colors.grey[600],
),
),
),
),
),
const SizedBox(width: 16),
Expanded(
child: InkWell(
onTap: _selectionnerHeureDebut,
child: InputDecorator(
decoration: const InputDecoration(
labelText: 'Heure de début *',
prefixIcon: Icon(Icons.access_time),
),
child: Text(
_heureDebut != null
? _heureDebut!.format(context)
: 'Sélectionner',
style: TextStyle(
color: _heureDebut != null ? null : Colors.grey[600],
),
),
),
),
),
],
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: InkWell(
onTap: _selectionnerDateFin,
child: InputDecorator(
decoration: const InputDecoration(
labelText: 'Date de fin',
prefixIcon: Icon(Icons.calendar_today),
),
child: Text(
_dateFin != null
? DateFormat('dd/MM/yyyy').format(_dateFin!)
: 'Optionnel',
style: TextStyle(
color: _dateFin != null ? null : Colors.grey[600],
),
),
),
),
),
const SizedBox(width: 16),
Expanded(
child: InkWell(
onTap: _selectionnerHeureFin,
child: InputDecorator(
decoration: const InputDecoration(
labelText: 'Heure de fin',
prefixIcon: Icon(Icons.access_time),
),
child: Text(
_heureFin != null
? _heureFin!.format(context)
: 'Optionnel',
style: TextStyle(
color: _heureFin != null ? null : Colors.grey[600],
),
),
),
),
),
],
),
],
),
),
);
}
Widget _buildLieuEtAdresse() {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Lieu et adresse',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 16),
TextFormField(
controller: _lieuController,
decoration: const InputDecoration(
labelText: 'Lieu *',
hintText: 'Ex: Salle des fêtes',
prefixIcon: Icon(Icons.place),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Le lieu est obligatoire';
}
return null;
},
textCapitalization: TextCapitalization.words,
),
const SizedBox(height: 16),
TextFormField(
controller: _adresseController,
decoration: const InputDecoration(
labelText: 'Adresse complète',
hintText: 'Ex: 123 Rue de la République, 75001 Paris',
prefixIcon: Icon(Icons.location_on),
),
maxLines: 2,
textCapitalization: TextCapitalization.words,
),
],
),
),
);
}
Widget _buildParametres() {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Paramètres',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 16),
SwitchListTile(
title: const Text('Visible au public'),
subtitle: const Text('L\'événement sera visible par tous'),
value: _visiblePublic,
onChanged: (value) {
setState(() {
_visiblePublic = value;
});
},
activeColor: AppTheme.primaryColor,
),
SwitchListTile(
title: const Text('Inscription requise'),
subtitle: const Text('Les participants doivent s\'inscrire'),
value: _inscriptionRequise,
onChanged: (value) {
setState(() {
_inscriptionRequise = value;
if (!value) {
_inscriptionPayante = false;
}
});
},
activeColor: AppTheme.primaryColor,
),
if (_inscriptionRequise)
SwitchListTile(
title: const Text('Inscription payante'),
subtitle: const Text('L\'inscription nécessite un paiement'),
value: _inscriptionPayante,
onChanged: (value) {
setState(() {
_inscriptionPayante = value;
});
},
activeColor: AppTheme.primaryColor,
),
const SizedBox(height: 16),
TextFormField(
controller: _capaciteMaxController,
decoration: const InputDecoration(
labelText: 'Capacité maximale',
hintText: 'Nombre maximum de participants',
prefixIcon: Icon(Icons.people),
suffixText: 'personnes',
),
keyboardType: TextInputType.number,
validator: (value) {
if (value != null && value.isNotEmpty) {
final capacite = int.tryParse(value);
if (capacite == null || capacite <= 0) {
return 'La capacité doit être un nombre positif';
}
}
return null;
},
),
if (_inscriptionPayante) ...[
const SizedBox(height: 16),
TextFormField(
controller: _prixController,
decoration: const InputDecoration(
labelText: 'Prix de l\'inscription *',
hintText: '0.00',
prefixIcon: Icon(Icons.euro),
suffixText: '',
),
keyboardType: const TextInputType.numberWithOptions(decimal: true),
validator: (value) {
if (_inscriptionPayante) {
if (value == null || value.trim().isEmpty) {
return 'Le prix est obligatoire pour une inscription payante';
}
final prix = double.tryParse(value.replaceAll(',', '.'));
if (prix == null || prix < 0) {
return 'Le prix doit être un nombre positif';
}
}
return null;
},
),
],
],
),
),
);
}
Widget _buildInformationsComplementaires() {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Informations complémentaires',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 16),
TextFormField(
controller: _notesController,
decoration: const InputDecoration(
labelText: 'Notes internes',
hintText: 'Notes visibles uniquement par les organisateurs...',
prefixIcon: Icon(Icons.note),
),
maxLines: 3,
textCapitalization: TextCapitalization.sentences,
),
],
),
),
);
}
// Méthodes de sélection de date et heure
Future<void> _selectionnerDateDebut() async {
final date = await showDatePicker(
context: context,
initialDate: _dateDebut ?? DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
);
if (date != null) {
setState(() {
_dateDebut = date;
// Si la date de fin est antérieure, la réinitialiser
if (_dateFin != null && _dateFin!.isBefore(date)) {
_dateFin = null;
}
});
}
}
Future<void> _selectionnerDateFin() async {
final date = await showDatePicker(
context: context,
initialDate: _dateFin ?? _dateDebut ?? DateTime.now(),
firstDate: _dateDebut ?? DateTime.now(),
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
);
if (date != null) {
setState(() {
_dateFin = date;
});
}
}
Future<void> _selectionnerHeureDebut() async {
final heure = await showTimePicker(
context: context,
initialTime: _heureDebut ?? TimeOfDay.now(),
);
if (heure != null) {
setState(() {
_heureDebut = heure;
});
}
}
Future<void> _selectionnerHeureFin() async {
final heure = await showTimePicker(
context: context,
initialTime: _heureFin ?? _heureDebut ?? TimeOfDay.now(),
);
if (heure != null) {
setState(() {
_heureFin = heure;
});
}
}
// Méthode de sauvegarde
void _sauvegarder() {
if (!_formKey.currentState!.validate()) {
// Faire défiler vers le premier champ en erreur
_scrollController.animateTo(
0,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
return;
}
// Validation des dates
if (_dateDebut == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('La date de début est obligatoire'),
backgroundColor: AppTheme.errorColor,
),
);
return;
}
if (_heureDebut == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('L\'heure de début est obligatoire'),
backgroundColor: AppTheme.errorColor,
),
);
return;
}
// Construire les DateTime complets
final dateTimeDebut = DateTime(
_dateDebut!.year,
_dateDebut!.month,
_dateDebut!.day,
_heureDebut!.hour,
_heureDebut!.minute,
);
DateTime? dateTimeFin;
if (_dateFin != null && _heureFin != null) {
dateTimeFin = DateTime(
_dateFin!.year,
_dateFin!.month,
_dateFin!.day,
_heureFin!.hour,
_heureFin!.minute,
);
// Vérifier que la date de fin est après le début
if (dateTimeFin.isBefore(dateTimeDebut)) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('La date de fin doit être après la date de début'),
backgroundColor: AppTheme.errorColor,
),
);
return;
}
}
// Créer l'objet événement
final evenement = EvenementModel(
id: null,
titre: _titreController.text.trim(),
description: _descriptionController.text.trim().isEmpty
? null
: _descriptionController.text.trim(),
typeEvenement: _typeSelectionne,
dateDebut: dateTimeDebut,
dateFin: dateTimeFin,
lieu: _lieuController.text.trim(),
adresse: _adresseController.text.trim().isEmpty
? null
: _adresseController.text.trim(),
capaciteMax: _capaciteMaxController.text.isEmpty
? null
: int.tryParse(_capaciteMaxController.text),
prix: _inscriptionPayante && _prixController.text.isNotEmpty
? double.tryParse(_prixController.text.replaceAll(',', '.'))
: null,
visiblePublic: _visiblePublic,
inscriptionRequise: _inscriptionRequise,
instructionsParticulieres: _notesController.text.trim().isEmpty
? null
: _notesController.text.trim(),
statut: StatutEvenement.planifie,
actif: true,
creePar: null, // Sera défini par le backend
dateCreation: null, // Sera défini par le backend
modifiePar: null,
dateModification: null,
organisationId: null, // Sera défini par le backend selon l'utilisateur connecté
organisateurId: null, // Sera défini par le backend selon l'utilisateur connecté
);
// Envoyer l'événement au BLoC
_evenementBloc.add(CreateEvenement(evenement));
}
}

View File

@@ -0,0 +1,426 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../../../../core/models/evenement_model.dart';
/// Page de détail d'un événement
class EvenementDetailPage extends StatelessWidget {
final EvenementModel evenement;
const EvenementDetailPage({
super.key,
required this.evenement,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final dateFormat = DateFormat('EEEE dd MMMM yyyy', 'fr_FR');
final timeFormat = DateFormat('HH:mm');
return Scaffold(
body: CustomScrollView(
slivers: [
// App Bar avec image de fond
SliverAppBar(
expandedHeight: 200,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text(
evenement.titre,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
shadows: [
Shadow(
offset: Offset(0, 1),
blurRadius: 3,
color: Colors.black54,
),
],
),
),
background: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
theme.primaryColor,
theme.primaryColor.withOpacity(0.8),
],
),
),
child: Center(
child: Text(
evenement.typeEvenement.icone,
style: const TextStyle(fontSize: 80),
),
),
),
),
actions: [
IconButton(
onPressed: () => _shareEvenement(context),
icon: const Icon(Icons.share),
),
PopupMenuButton<String>(
onSelected: (value) {
switch (value) {
case 'calendar':
_addToCalendar(context);
break;
case 'favorite':
_toggleFavorite(context);
break;
}
},
itemBuilder: (context) => [
const PopupMenuItem(
value: 'calendar',
child: Row(
children: [
Icon(Icons.calendar_today),
SizedBox(width: 8),
Text('Ajouter au calendrier'),
],
),
),
const PopupMenuItem(
value: 'favorite',
child: Row(
children: [
Icon(Icons.favorite_border),
SizedBox(width: 8),
Text('Ajouter aux favoris'),
],
),
),
],
),
],
),
// Contenu principal
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Statut et type
Row(
children: [
_buildStatutChip(context),
const SizedBox(width: 8),
Chip(
label: Text(evenement.typeEvenement.libelle),
backgroundColor: theme.primaryColor.withOpacity(0.1),
),
],
),
const SizedBox(height: 16),
// Description
if (evenement.description != null) ...[
Text(
'Description',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
evenement.description!,
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 24),
],
// Informations pratiques
_buildSectionTitle(context, 'Informations pratiques'),
const SizedBox(height: 12),
_buildInfoRow(
context,
Icons.schedule,
'Date et heure',
'${dateFormat.format(evenement.dateDebut)}\n'
'${timeFormat.format(evenement.dateDebut)}'
'${evenement.dateFin != null ? ' - ${timeFormat.format(evenement.dateFin!)}' : ''}',
),
if (evenement.lieu != null)
_buildInfoRow(
context,
Icons.location_on,
'Lieu',
evenement.lieu!,
),
if (evenement.adresse != null)
_buildInfoRow(
context,
Icons.map,
'Adresse',
evenement.adresse!,
),
if (evenement.duree != null)
_buildInfoRow(
context,
Icons.timer,
'Durée',
evenement.dureeFormatee,
),
if (evenement.prix != null)
_buildInfoRow(
context,
Icons.euro,
'Prix',
evenement.prix! > 0
? '${evenement.prix!.toStringAsFixed(0)}'
: 'Gratuit',
),
if (evenement.capaciteMax != null)
_buildInfoRow(
context,
Icons.people,
'Capacité',
'${evenement.capaciteMax} personnes',
),
const SizedBox(height: 24),
// Inscription
if (evenement.inscriptionRequise) ...[
_buildSectionTitle(context, 'Inscription'),
const SizedBox(height: 12),
if (evenement.inscriptionsOuvertes) ...[
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.green.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.green.withOpacity(0.3)),
),
child: Column(
children: [
const Icon(
Icons.check_circle,
color: Colors.green,
size: 32,
),
const SizedBox(height: 8),
const Text(
'Inscriptions ouvertes',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
),
),
if (evenement.dateLimiteInscription != null) ...[
const SizedBox(height: 4),
Text(
'Jusqu\'au ${dateFormat.format(evenement.dateLimiteInscription!)}',
style: TextStyle(
color: Colors.green[700],
fontSize: 12,
),
),
],
],
),
),
] else ...[
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.red.withOpacity(0.3)),
),
child: const Column(
children: [
Icon(
Icons.cancel,
color: Colors.red,
size: 32,
),
SizedBox(height: 8),
Text(
'Inscriptions fermées',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red,
),
),
],
),
),
],
const SizedBox(height: 24),
],
// Instructions particulières
if (evenement.instructionsParticulieres != null) ...[
_buildSectionTitle(context, 'Instructions particulières'),
const SizedBox(height: 8),
Text(
evenement.instructionsParticulieres!,
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 24),
],
// Matériel requis
if (evenement.materielRequis != null) ...[
_buildSectionTitle(context, 'Matériel requis'),
const SizedBox(height: 8),
Text(
evenement.materielRequis!,
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 24),
],
// Contact organisateur
if (evenement.contactOrganisateur != null) ...[
_buildSectionTitle(context, 'Contact organisateur'),
const SizedBox(height: 8),
Text(
evenement.contactOrganisateur!,
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 24),
],
// Espace pour le bouton flottant
const SizedBox(height: 80),
],
),
),
),
],
),
// Bouton d'action flottant
floatingActionButton: evenement.inscriptionRequise &&
evenement.inscriptionsOuvertes
? FloatingActionButton.extended(
onPressed: () => _inscrireAEvenement(context),
icon: const Icon(Icons.how_to_reg),
label: const Text('S\'inscrire'),
)
: null,
);
}
Widget _buildStatutChip(BuildContext context) {
final color = Color(int.parse(
evenement.statut.couleur.substring(1),
radix: 16,
) + 0xFF000000);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: color.withOpacity(0.3)),
),
child: Text(
evenement.statut.libelle,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: color,
),
),
);
}
Widget _buildSectionTitle(BuildContext context, String title) {
return Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
);
}
Widget _buildInfoRow(
BuildContext context,
IconData icon,
String label,
String value,
) {
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
icon,
size: 20,
color: Colors.grey[600],
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey[600],
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 2),
Text(
value,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
],
),
);
}
void _shareEvenement(BuildContext context) {
// TODO: Implémenter le partage
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Partage - À implémenter')),
);
}
void _addToCalendar(BuildContext context) {
// TODO: Implémenter l'ajout au calendrier
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Ajout au calendrier - À implémenter')),
);
}
void _toggleFavorite(BuildContext context) {
// TODO: Implémenter les favoris
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Favoris - À implémenter')),
);
}
void _inscrireAEvenement(BuildContext context) {
// TODO: Implémenter l'inscription
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Inscription - À implémenter')),
);
}
}

View File

@@ -0,0 +1,382 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../core/di/injection.dart';
import '../../../../core/models/evenement_model.dart';
import '../../../../shared/theme/app_theme.dart';
import '../bloc/evenement_bloc.dart';
import '../bloc/evenement_event.dart';
import '../bloc/evenement_state.dart';
import '../widgets/evenement_card.dart';
import '../widgets/evenement_search_bar.dart';
import '../widgets/evenement_filter_chips.dart';
import 'evenement_detail_page.dart';
import 'evenement_create_page.dart';
/// Page principale des événements
class EvenementsPage extends StatelessWidget {
const EvenementsPage({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => getIt<EvenementBloc>()
..add(const LoadEvenementsAVenir()),
child: const _EvenementsPageContent(),
);
}
}
class _EvenementsPageContent extends StatefulWidget {
const _EvenementsPageContent();
@override
State<_EvenementsPageContent> createState() => _EvenementsPageContentState();
}
class _EvenementsPageContentState extends State<_EvenementsPageContent>
with TickerProviderStateMixin {
late TabController _tabController;
final ScrollController _scrollController = ScrollController();
String _searchTerm = '';
TypeEvenement? _selectedType;
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
_scrollController.addListener(_onScroll);
_tabController.addListener(() {
if (_tabController.indexIsChanging) {
_onTabChanged(_tabController.index);
}
});
}
@override
void dispose() {
_tabController.dispose();
_scrollController.dispose();
super.dispose();
}
void _onScroll() {
if (_isBottom) {
final bloc = context.read<EvenementBloc>();
final state = bloc.state;
if (state is EvenementLoaded && !state.hasReachedMax) {
_loadMoreEvents(state);
}
}
}
bool get _isBottom {
if (!_scrollController.hasClients) return false;
final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.offset;
return currentScroll >= (maxScroll * 0.9);
}
void _loadMoreEvents(EvenementLoaded state) {
final nextPage = state.currentPage + 1;
switch (_tabController.index) {
case 0:
context.read<EvenementBloc>().add(
LoadEvenementsAVenir(page: nextPage),
);
break;
case 1:
context.read<EvenementBloc>().add(
LoadEvenementsPublics(page: nextPage),
);
break;
case 2:
if (_searchTerm.isNotEmpty) {
context.read<EvenementBloc>().add(
SearchEvenements(terme: _searchTerm, page: nextPage),
);
} else if (_selectedType != null) {
context.read<EvenementBloc>().add(
FilterEvenementsByType(type: _selectedType!, page: nextPage),
);
} else {
context.read<EvenementBloc>().add(
LoadEvenements(page: nextPage),
);
}
break;
}
}
void _onTabChanged(int index) {
context.read<EvenementBloc>().add(const ResetEvenementState());
switch (index) {
case 0:
context.read<EvenementBloc>().add(const LoadEvenementsAVenir());
break;
case 1:
context.read<EvenementBloc>().add(const LoadEvenementsPublics());
break;
case 2:
context.read<EvenementBloc>().add(const LoadEvenements());
break;
}
}
void _onSearch(String terme) {
setState(() {
_searchTerm = terme;
_selectedType = null;
});
if (terme.isNotEmpty) {
context.read<EvenementBloc>().add(
SearchEvenements(terme: terme, refresh: true),
);
} else {
context.read<EvenementBloc>().add(
const LoadEvenements(refresh: true),
);
}
}
void _onFilterByType(TypeEvenement? type) {
setState(() {
_selectedType = type;
_searchTerm = '';
});
if (type != null) {
context.read<EvenementBloc>().add(
FilterEvenementsByType(type: type, refresh: true),
);
} else {
context.read<EvenementBloc>().add(
const LoadEvenements(refresh: true),
);
}
}
void _onRefresh() {
switch (_tabController.index) {
case 0:
context.read<EvenementBloc>().add(
const LoadEvenementsAVenir(refresh: true),
);
break;
case 1:
context.read<EvenementBloc>().add(
const LoadEvenementsPublics(refresh: true),
);
break;
case 2:
if (_searchTerm.isNotEmpty) {
context.read<EvenementBloc>().add(
SearchEvenements(terme: _searchTerm, refresh: true),
);
} else if (_selectedType != null) {
context.read<EvenementBloc>().add(
FilterEvenementsByType(type: _selectedType!, refresh: true),
);
} else {
context.read<EvenementBloc>().add(
const LoadEvenements(refresh: true),
);
}
break;
}
}
void _navigateToDetail(EvenementModel evenement) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => EvenementDetailPage(evenement: evenement),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Événements'),
backgroundColor: Theme.of(context).primaryColor,
foregroundColor: Colors.white,
bottom: TabBar(
controller: _tabController,
tabs: const [
Tab(text: 'À venir', icon: Icon(Icons.upcoming)),
Tab(text: 'Publics', icon: Icon(Icons.public)),
Tab(text: 'Tous', icon: Icon(Icons.list)),
],
),
),
body: TabBarView(
controller: _tabController,
children: [
_buildEvenementsList(showSearch: false),
_buildEvenementsList(showSearch: false),
_buildEvenementsList(showSearch: true),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
final result = await Navigator.of(context).push<bool>(
MaterialPageRoute(
builder: (context) => const EvenementCreatePage(),
),
);
// Si un événement a été créé, recharger la liste
if (result == true && context.mounted) {
context.read<EvenementBloc>().add(const LoadEvenementsAVenir());
}
},
child: const Icon(Icons.add),
),
);
}
Widget _buildEvenementsList({required bool showSearch}) {
return Column(
children: [
if (showSearch) ...[
Padding(
padding: const EdgeInsets.all(16.0),
child: EvenementSearchBar(
onSearch: _onSearch,
initialValue: _searchTerm,
),
),
EvenementFilterChips(
selectedType: _selectedType,
onTypeSelected: _onFilterByType,
),
],
Expanded(
child: BlocConsumer<EvenementBloc, EvenementState>(
listener: (context, state) {
if (state is EvenementError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
backgroundColor: Colors.red,
),
);
}
},
builder: (context, state) {
if (state is EvenementLoading) {
return const Center(child: CircularProgressIndicator());
}
if (state is EvenementError && state.evenements == null) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline, size: 64, color: Colors.red),
const SizedBox(height: 16),
Text(state.message, textAlign: TextAlign.center),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _onRefresh,
child: const Text('Réessayer'),
),
],
),
);
}
if (state is EvenementSearchEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.search_off,
size: 64,
color: Colors.grey,
),
const SizedBox(height: 16),
Text(
'Aucun résultat pour "${state.searchTerm}"',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
const Text('Essayez avec d\'autres mots-clés'),
],
),
);
}
if (state is EvenementEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.event_busy,
size: 64,
color: Colors.grey,
),
const SizedBox(height: 16),
Text(
state.message,
style: Theme.of(context).textTheme.titleMedium,
),
],
),
);
}
final evenements = state is EvenementLoaded
? state.evenements
: state is EvenementLoadingMore
? state.evenements
: state is EvenementError
? state.evenements ?? <EvenementModel>[]
: <EvenementModel>[];
if (evenements.isEmpty) {
return const Center(
child: Text('Aucun événement disponible'),
);
}
return RefreshIndicator(
onRefresh: () async => _onRefresh(),
child: ListView.builder(
controller: _scrollController,
padding: const EdgeInsets.all(16),
itemCount: evenements.length +
(state is EvenementLoadingMore ? 1 : 0),
itemBuilder: (context, index) {
if (index >= evenements.length) {
return const Padding(
padding: EdgeInsets.all(16),
child: Center(child: CircularProgressIndicator()),
);
}
final evenement = evenements[index];
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: EvenementCard(
evenement: evenement,
onTap: () => _navigateToDetail(evenement),
),
);
},
),
);
},
),
),
],
);
}
}