Refactoring : Fonctionnalité de Création d'un évènement est OK.
This commit is contained in:
@@ -2,14 +2,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:afterwork/data/models/creator_model.dart';
|
||||
import 'package:afterwork/data/models/event_model.dart';
|
||||
import 'package:afterwork/data/models/participant_model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:afterwork/data/providers/user_provider.dart';
|
||||
import 'package:afterwork/data/models/user_model.dart';
|
||||
import 'package:afterwork/core/constants/urls.dart';
|
||||
import '../location/location_picker_screen.dart';
|
||||
|
||||
/// Classe représentant la boîte de dialogue pour ajouter un nouvel événement.
|
||||
/// Cette boîte de dialogue permet à l'utilisateur de remplir les détails d'un nouvel événement.
|
||||
class AddEventDialog extends StatefulWidget {
|
||||
final String userId;
|
||||
final String userName;
|
||||
@@ -27,15 +26,15 @@ class AddEventDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AddEventDialogState extends State<AddEventDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _formKey = GlobalKey<FormState>(); // Clé globale pour valider le formulaire
|
||||
String _title = '';
|
||||
String _description = '';
|
||||
DateTime? _selectedDate;
|
||||
String? _imagePath;
|
||||
String _location = 'Abidjan'; // Par défaut à Cocody, Abidjan
|
||||
String _location = 'Abidjan'; // Par défaut à Cocody, Abidjan
|
||||
String _category = '';
|
||||
String _link = '';
|
||||
LatLng? _selectedLatLng = const LatLng(5.348722, -3.985038); // Par défaut à Cocody, Abidjan
|
||||
LatLng? _selectedLatLng = const LatLng(5.348722, -3.985038); // Par défaut à Cocody, Abidjan
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -48,7 +47,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
key: _formKey, // Formulaire clé pour valider l'entrée des utilisateurs
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -75,6 +74,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de saisie du titre de l'événement.
|
||||
Widget _buildTitleField() {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
@@ -103,6 +103,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de saisie de la description de l'événement.
|
||||
Widget _buildDescriptionField() {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
@@ -132,6 +133,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Widget pour le sélecteur de date pour l'événement.
|
||||
Widget _buildDatePicker() {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
@@ -172,6 +174,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de localisation pour l'événement.
|
||||
Widget _buildLocationField(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
@@ -213,6 +216,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de saisie de la catégorie de l'événement.
|
||||
Widget _buildCategoryField() {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
@@ -234,6 +238,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de sélection d'image pour l'événement.
|
||||
Widget _buildImagePicker() {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
@@ -262,6 +267,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du champ de saisie du lien associé à l'événement.
|
||||
Widget _buildLinkField() {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
@@ -283,6 +289,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction du bouton de soumission pour ajouter l'événement.
|
||||
Widget _buildSubmitButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () async {
|
||||
@@ -292,6 +299,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
|
||||
// Créer l'événement en utilisant l'ID réel de l'utilisateur pour le créateur et les participants
|
||||
EventModel newEvent = EventModel(
|
||||
id: '',
|
||||
title: _title,
|
||||
description: _description,
|
||||
date: _selectedDate?.toIso8601String() ?? '',
|
||||
@@ -299,19 +307,22 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
category: _category,
|
||||
link: _link,
|
||||
imageUrl: _imagePath ?? '',
|
||||
creator: CreatorModel(
|
||||
id: widget.userId,
|
||||
creator: UserModel(
|
||||
userId: widget.userId,
|
||||
nom: widget.userName,
|
||||
prenoms: widget.userLastName,
|
||||
email: '',
|
||||
motDePasse: '',
|
||||
),
|
||||
participants: [
|
||||
ParticipantModel(
|
||||
id: widget.userId,
|
||||
UserModel(
|
||||
userId: widget.userId,
|
||||
nom: widget.userName,
|
||||
prenoms: widget.userLastName,
|
||||
email: '',
|
||||
motDePasse: '',
|
||||
)
|
||||
],
|
||||
id: '',
|
||||
);
|
||||
|
||||
// Convertir l'événement en JSON
|
||||
@@ -331,7 +342,7 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
if (response.statusCode == 201) {
|
||||
// Création réussie
|
||||
print('Événement créé avec succès');
|
||||
Navigator.of(context).pop(true);
|
||||
Navigator.of(context).pop(); // Ne passez pas de valeur ici
|
||||
} else {
|
||||
// Gérer l'erreur
|
||||
print('Erreur lors de la création de l\'événement: ${response.reasonPhrase}');
|
||||
@@ -351,8 +362,8 @@ class _AddEventDialogState extends State<AddEventDialog> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
||||
minimumSize: const Size(double.infinity, 40),
|
||||
),
|
||||
child: const Text('Ajouter l\'événement',
|
||||
style: TextStyle(color: Colors.white)),
|
||||
child: const Text('Ajouter l\'événement', style: TextStyle(color: Colors.white)),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user