Refactoring + Version améliorée
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:afterwork/presentation/screens/login/login_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/event/event_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/story/story_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/profile/profile_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/settings/settings_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/home/home_screen.dart';
|
||||
import 'package:afterwork/presentation/screens/event/event_screen.dart';
|
||||
import 'package:afterwork/data/datasources/event_remote_data_source.dart';
|
||||
import '../presentation/reservations/reservations_screen.dart';
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class AppColors {
|
||||
static const Color lightError = Color(0xFFB00020);
|
||||
static const Color lightIconPrimary = Color(0xFF212121); // Icône primaire sombre
|
||||
static const Color lightIconSecondary = Color(0xFF757575); // Icône secondaire gris clair
|
||||
|
||||
// Thème sombre
|
||||
static const Color darkPrimary = Color(0xFF121212);
|
||||
static const Color darkSecondary = Color(0xFFFF5722);
|
||||
@@ -31,6 +32,9 @@ class AppColors {
|
||||
static const Color darkIconPrimary = Colors.white; // Icône primaire blanche
|
||||
static const Color darkIconSecondary = Color(0xFFBDBDBD); // Icône secondaire gris clair
|
||||
|
||||
// Ajout du background personnalisé
|
||||
static const Color backgroundCustom = Color(0xFF2C2C3E);
|
||||
|
||||
// Sélection automatique des couleurs en fonction du mode de thème
|
||||
static Color get primary => isDarkMode() ? darkPrimary : lightPrimary;
|
||||
static Color get secondary => isDarkMode() ? darkSecondary : lightSecondary;
|
||||
@@ -45,6 +49,7 @@ class AppColors {
|
||||
static Color get errorColor => isDarkMode() ? darkError : lightError;
|
||||
static Color get iconPrimary => isDarkMode() ? darkIconPrimary : lightIconPrimary;
|
||||
static Color get iconSecondary => isDarkMode() ? darkIconSecondary : lightIconSecondary;
|
||||
static Color get customBackgroundColor => backgroundCustom;
|
||||
|
||||
/// Méthode utilitaire pour vérifier si le mode sombre est activé.
|
||||
static bool isDarkMode() {
|
||||
|
||||
@@ -17,6 +17,7 @@ class Urls {
|
||||
static const String removeParticipant = '$baseUrl/events'; // Append '/{id}/participants/{userId}' dynamically
|
||||
static const String getNumberOfParticipants = '$baseUrl/events'; // Append '/{id}/participants/count' dynamically
|
||||
static const String closeEvent = '$baseUrl/events'; // Append '/{id}/close' dynamically
|
||||
static const String reopenEvent = '$baseUrl/events'; // Append '/{id}/reopen' dynamically
|
||||
static const String updateEvent = '$baseUrl/events'; // Append '/{id}' dynamically
|
||||
static const String updateEventImage = '$baseUrl/events'; // Append '/{id}/image' dynamically
|
||||
static const String getAllEvents = '$baseUrl/events';
|
||||
|
||||
@@ -174,7 +174,7 @@ class EventRemoteDataSource {
|
||||
print('Réouverture de l\'événement avec l\'ID: $eventId');
|
||||
|
||||
final response = await client.post(
|
||||
Uri.parse('${Urls.baseUrl}/$eventId/reopen'),
|
||||
Uri.parse('${Urls.reopenEvent}/$eventId/reopen'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class EventModel {
|
||||
final String category;
|
||||
final String link;
|
||||
final String? imageUrl; // Nullable
|
||||
final String creatorEmail; // Remplacer UserModel si le créateur est un email
|
||||
final String creatorEmail;
|
||||
final List<dynamic> participants; // Si participants est une liste simple
|
||||
final String status;
|
||||
final int reactionsCount;
|
||||
@@ -43,7 +43,7 @@ class EventModel {
|
||||
imageUrl: json['imageUrl'], // Peut être null
|
||||
creatorEmail: json['creatorEmail'], // Email du créateur
|
||||
participants: json['participants'] ?? [], // Gérer les participants
|
||||
status: json['status'] ?? 'open', // Par défaut à "open" si non fourni
|
||||
status: json['status'] ?? 'ouvert', // Par défaut à "ouvert" si non fourni
|
||||
reactionsCount: json['reactionsCount'] ?? 0,
|
||||
commentsCount: json['commentsCount'] ?? 0,
|
||||
sharesCount: json['sharesCount'] ?? 0,
|
||||
|
||||
@@ -1,110 +1,118 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'dart:io';
|
||||
|
||||
/// Dialogue pour ajouter un nouvel événement.
|
||||
/// Ce widget affiche un formulaire permettant à l'utilisateur de saisir les détails d'un événement.
|
||||
/// Les logs permettent de suivre les actions de l'utilisateur dans ce dialogue.
|
||||
class AddEventDialog extends StatefulWidget {
|
||||
import '../../widgets/category_field.dart';
|
||||
import '../../widgets/date_picker.dart';
|
||||
import '../../widgets/description_field.dart';
|
||||
import '../../widgets/link_field.dart';
|
||||
import '../../widgets/location_field.dart';
|
||||
import '../../widgets/submit_button.dart';
|
||||
import '../../widgets/title_field.dart';
|
||||
import '../../widgets/image_preview_picker.dart';
|
||||
|
||||
class AddEventPage extends StatefulWidget {
|
||||
final String userId;
|
||||
final String userName;
|
||||
final String userLastName;
|
||||
|
||||
const AddEventDialog({
|
||||
Key? key,
|
||||
const AddEventPage({
|
||||
super.key,
|
||||
required this.userId,
|
||||
required this.userName,
|
||||
required this.userLastName,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
_AddEventDialogState createState() => _AddEventDialogState();
|
||||
_AddEventPageState createState() => _AddEventPageState();
|
||||
}
|
||||
|
||||
class _AddEventDialogState extends State<AddEventDialog> {
|
||||
final _formKey = GlobalKey<FormState>(); // Clé pour valider le formulaire
|
||||
String _eventName = ''; // Nom de l'événement
|
||||
DateTime _selectedDate = DateTime.now(); // Date de l'événement
|
||||
class _AddEventPageState extends State<AddEventPage> {
|
||||
final _formKey = GlobalKey<FormState>(); // Form key for validation
|
||||
|
||||
String _title = '';
|
||||
String _description = '';
|
||||
DateTime? _selectedDate;
|
||||
String _location = 'Abidjan';
|
||||
String _category = '';
|
||||
String _link = '';
|
||||
LatLng? _selectedLatLng = const LatLng(5.348722, -3.985038); // Default coordinates
|
||||
File? _selectedImageFile; // Store the selected image
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print("Affichage du dialogue d'ajout d'événement.");
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Ajouter un événement'),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Champ pour entrer le nom de l'événement
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(labelText: 'Nom de l\'événement'),
|
||||
onSaved: (value) {
|
||||
_eventName = value ?? '';
|
||||
print("Nom de l'événement saisi : $_eventName");
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
print("Erreur : le champ du nom de l'événement est vide.");
|
||||
return 'Veuillez entrer un nom d\'événement';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Sélecteur de date pour l'événement
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final selectedDate = await _selectDate(context);
|
||||
if (selectedDate != null) {
|
||||
setState(() {
|
||||
_selectedDate = selectedDate;
|
||||
print("Date de l'événement sélectionnée : $_selectedDate");
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text('Sélectionner la date : ${_selectedDate.toLocal()}'.split(' ')[0]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
// Bouton pour annuler l'ajout de l'événement
|
||||
TextButton(
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Ajouter un événement'),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
print("L'utilisateur a annulé l'ajout de l'événement.");
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
// Bouton pour soumettre le formulaire et ajouter l'événement
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState?.validate() == true) {
|
||||
_formKey.currentState?.save();
|
||||
print("L'utilisateur a ajouté un événement : Nom = $_eventName, Date = $_selectedDate");
|
||||
Navigator.of(context).pop({
|
||||
'eventName': _eventName,
|
||||
'eventDate': _selectedDate,
|
||||
});
|
||||
}
|
||||
},
|
||||
child: const Text('Ajouter'),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ImagePreviewPicker(
|
||||
onImagePicked: (File? imageFile) {
|
||||
setState(() {
|
||||
_selectedImageFile = imageFile;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TitleField(onSaved: (value) => setState(() => _title = value ?? '')),
|
||||
const SizedBox(height: 12),
|
||||
DescriptionField(onSaved: (value) => setState(() => _description = value ?? '')),
|
||||
const SizedBox(height: 12),
|
||||
DatePickerField(
|
||||
selectedDate: _selectedDate,
|
||||
onDatePicked: (picked) => setState(() {
|
||||
_selectedDate = picked;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
LocationField(
|
||||
location: _location,
|
||||
selectedLatLng: _selectedLatLng,
|
||||
onLocationPicked: (pickedLocation) => setState(() {
|
||||
_selectedLatLng = pickedLocation;
|
||||
_location = '${pickedLocation?.latitude}, ${pickedLocation?.longitude}';
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
CategoryField(onSaved: (value) => setState(() => _category = value ?? '')),
|
||||
const SizedBox(height: 12),
|
||||
LinkField(onSaved: (value) => setState(() => _link = value ?? '')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Bouton en bas de l'écran
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SubmitButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
// Logic to add the event goes here
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Fonction pour afficher le sélecteur de date
|
||||
Future<DateTime?> _selectDate(BuildContext context) async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (picked != null) {
|
||||
print("Date choisie dans le sélecteur : $picked");
|
||||
}
|
||||
return picked;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:afterwork/data/models/event_model.dart';
|
||||
import 'package:afterwork/core/utils/date_formatter.dart'; // Importer DateFormatter
|
||||
|
||||
/// Widget pour afficher une carte d'événement.
|
||||
import '../../../data/models/event_model.dart';
|
||||
import '../../widgets/event_header.dart';
|
||||
import '../../widgets/event_image.dart';
|
||||
import '../../widgets/event_interaction_row.dart';
|
||||
import '../../widgets/event_status_badge.dart';
|
||||
import '../../widgets/swipe_background.dart';
|
||||
|
||||
class EventCard extends StatelessWidget {
|
||||
final EventModel event;
|
||||
final String userId;
|
||||
final String userName;
|
||||
final String userLastName;
|
||||
final String status;
|
||||
final VoidCallback onReact;
|
||||
final VoidCallback onComment;
|
||||
final VoidCallback onShare;
|
||||
final VoidCallback onParticipate;
|
||||
final VoidCallback onCloseEvent;
|
||||
final VoidCallback onReopenEvent;
|
||||
final Function onRemoveEvent;
|
||||
|
||||
const EventCard({
|
||||
Key? key,
|
||||
@@ -21,152 +27,93 @@ class EventCard extends StatelessWidget {
|
||||
required this.userId,
|
||||
required this.userName,
|
||||
required this.userLastName,
|
||||
required this.status,
|
||||
required this.onReact,
|
||||
required this.onComment,
|
||||
required this.onShare,
|
||||
required this.onParticipate,
|
||||
required this.onCloseEvent,
|
||||
required this.onReopenEvent,
|
||||
required this.onRemoveEvent,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
color: const Color(0xFF2C2C3E),
|
||||
margin: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
event.title,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
event.description,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildEventImage(),
|
||||
const Divider(color: Colors.white24),
|
||||
_buildInteractionRow(),
|
||||
const SizedBox(height: 10),
|
||||
_buildStatusAndActions(),
|
||||
],
|
||||
),
|
||||
final GlobalKey menuKey = GlobalKey();
|
||||
|
||||
return Dismissible(
|
||||
key: ValueKey(event.id),
|
||||
direction: event.status == 'fermé'
|
||||
? DismissDirection.startToEnd
|
||||
: DismissDirection.endToStart,
|
||||
onDismissed: (direction) {
|
||||
if (event.status == 'fermé') {
|
||||
onReopenEvent();
|
||||
} else {
|
||||
onCloseEvent();
|
||||
onRemoveEvent(event.id);
|
||||
}
|
||||
},
|
||||
background: SwipeBackground(
|
||||
color: event.status == 'fermé' ? Colors.green : Colors.red,
|
||||
icon: event.status == 'fermé' ? Icons.lock_open : Icons.lock,
|
||||
label: event.status == 'fermé' ? 'Rouvrir' : 'Fermer',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
// Convertir la date de l'événement (de String à DateTime)
|
||||
DateTime? eventDate;
|
||||
try {
|
||||
eventDate = DateTime.parse(event.startDate);
|
||||
} catch (e) {
|
||||
eventDate = null; // Gérer le cas où la date ne serait pas valide
|
||||
}
|
||||
|
||||
// Utiliser DateFormatter pour afficher une date lisible si elle est valide
|
||||
String formattedDate = eventDate != null ? DateFormatter.formatDate(eventDate) : 'Date inconnue';
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
CircleAvatar(backgroundImage: NetworkImage(event.imageUrl ?? 'lib/assets/images/placeholder.png')),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$userName $userLastName',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
formattedDate, // Utiliser la date formatée ici
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.more_vert, color: Colors.white),
|
||||
onPressed: () {
|
||||
// Logique d'affichage d'options supplémentaires pour l'événement.
|
||||
// Vous pouvez utiliser un menu déroulant ou une boîte de dialogue ici.
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventImage() {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
child: Image.network(
|
||||
event.imageUrl ?? 'lib/assets/images/placeholder.png',
|
||||
height: 180,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Image.asset('lib/assets/images/placeholder.png'); // Image par défaut si erreur de chargement
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInteractionRow() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildIconButton(Icons.thumb_up_alt_outlined, 'Réagir', event.reactionsCount, onReact),
|
||||
_buildIconButton(Icons.comment_outlined, 'Commenter', event.commentsCount, onComment),
|
||||
_buildIconButton(Icons.share_outlined, 'Partager', event.sharesCount, onShare),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton(IconData icon, String label, int count, VoidCallback onPressed) {
|
||||
return TextButton.icon(
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon, color: const Color(0xFF1DBF73), size: 20),
|
||||
label: Text(
|
||||
'$label ($count)',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget pour afficher le statut de l'événement et les actions associées (fermer, réouvrir)
|
||||
Widget _buildStatusAndActions() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
event.status == 'closed' ? 'Événement fermé' : 'Événement ouvert',
|
||||
style: TextStyle(
|
||||
color: event.status == 'closed' ? Colors.red : Colors.green,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
child: Card(
|
||||
color: const Color(0xFF2C2C3E),
|
||||
margin: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
EventHeader(
|
||||
userName: userName,
|
||||
userLastName: userLastName,
|
||||
eventDate: event.startDate,
|
||||
imageUrl: event.imageUrl,
|
||||
menuKey: menuKey,
|
||||
menuContext: context,
|
||||
location: event.location,
|
||||
),
|
||||
const Divider(color: Colors.white24),
|
||||
Row(
|
||||
children: [
|
||||
const Spacer(), // Pusher le badge statut à la droite.
|
||||
EventStatusBadge(status: status),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
event.title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
event.description,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
EventImage(imageUrl: event.imageUrl),
|
||||
const Divider(color: Colors.white24),
|
||||
EventInteractionRow(
|
||||
onReact: onReact,
|
||||
onComment: onComment,
|
||||
onShare: onShare,
|
||||
reactionsCount: event.reactionsCount,
|
||||
commentsCount: event.commentsCount,
|
||||
sharesCount: event.sharesCount,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
event.status == 'closed'
|
||||
? ElevatedButton(
|
||||
onPressed: onReopenEvent,
|
||||
child: const Text('Rouvrir l\'événement'),
|
||||
)
|
||||
: ElevatedButton(
|
||||
onPressed: onCloseEvent,
|
||||
child: const Text('Fermer l\'événement'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:afterwork/data/models/event_model.dart';
|
||||
import 'package:afterwork/presentation/screens/event/event_card.dart';
|
||||
import '../../state_management/event_bloc.dart';
|
||||
import '../dialogs/add_event_dialog.dart';
|
||||
import '../../state_management/event_bloc.dart';
|
||||
|
||||
class EventScreen extends StatefulWidget {
|
||||
final String userId;
|
||||
@@ -43,25 +43,18 @@ class _EventScreenState extends State<EventScreen> {
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline, size: 28, color: Color(0xFF1DBF73)),
|
||||
onPressed: () async {
|
||||
final eventData = await showDialog<Map<String, dynamic>>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AddEventDialog(
|
||||
onPressed: () {
|
||||
// Naviguer vers une nouvelle page pour ajouter un événement
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AddEventPage(
|
||||
userId: widget.userId,
|
||||
userName: widget.userName,
|
||||
userLastName: widget.userLastName,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (eventData != null) {
|
||||
// Ajouter l'événement en appelant l'API via le bloc
|
||||
context.read<EventBloc>().add(AddEvent(EventModel.fromJson(eventData)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Événement ajouté avec succès !')),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -92,7 +85,17 @@ class _EventScreenState extends State<EventScreen> {
|
||||
onParticipate: () => _onParticipate(event.id),
|
||||
onCloseEvent: () => _onCloseEvent(event.id),
|
||||
onReopenEvent: () => _onReopenEvent(event.id),
|
||||
onRemoveEvent: (String eventId) {
|
||||
// Retirer l'événement localement après la fermeture
|
||||
setState(() {
|
||||
// Logique pour retirer l'événement de la liste localement
|
||||
// Par exemple, vous pouvez appeler le bloc ou mettre à jour l'état local ici
|
||||
context.read<EventBloc>().add(RemoveEvent(eventId));
|
||||
});
|
||||
},
|
||||
status: event.status,
|
||||
);
|
||||
|
||||
},
|
||||
);
|
||||
} else if (state is EventError) {
|
||||
|
||||
@@ -3,7 +3,6 @@ import '../../../core/constants/colors.dart'; // Importez les couleurs dynamique
|
||||
import '../../widgets/friend_suggestions.dart';
|
||||
import '../../widgets/group_list.dart';
|
||||
import '../../widgets/popular_activity_list.dart';
|
||||
import '../../widgets/quick_action_button.dart';
|
||||
import '../../widgets/recommended_event_list.dart';
|
||||
import '../../widgets/section_header.dart';
|
||||
import '../../widgets/story_section.dart';
|
||||
|
||||
@@ -59,6 +59,7 @@ class EventBloc extends Bloc<EventEvent, EventState> {
|
||||
on<AddEvent>(_onAddEvent);
|
||||
on<CloseEvent>(_onCloseEvent);
|
||||
on<ReopenEvent>(_onReopenEvent);
|
||||
on<RemoveEvent>(_onRemoveEvent); // Ajout du gestionnaire pour RemoveEvent
|
||||
}
|
||||
|
||||
// Gestion du chargement des événements
|
||||
@@ -107,4 +108,21 @@ class EventBloc extends Bloc<EventEvent, EventState> {
|
||||
emit(EventError('Erreur lors de la réouverture de l\'événement.'));
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion de la suppression locale d'un événement
|
||||
Future<void> _onRemoveEvent(RemoveEvent event, Emitter<EventState> emit) async {
|
||||
if (state is EventLoaded) {
|
||||
// Supprimer l'événement de la liste locale sans recharger tout
|
||||
final List<EventModel> updatedEvents = List.from((state as EventLoaded).events)
|
||||
..removeWhere((e) => e.id == event.eventId);
|
||||
emit(EventLoaded(updatedEvents));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveEvent extends EventEvent {
|
||||
final String eventId;
|
||||
|
||||
RemoveEvent(this.eventId);
|
||||
}
|
||||
|
||||
|
||||
119
lib/presentation/widgets/category_field.dart
Normal file
119
lib/presentation/widgets/category_field.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' as rootBundle;
|
||||
|
||||
class CategoryField extends StatefulWidget {
|
||||
final FormFieldSetter<String> onSaved;
|
||||
|
||||
const CategoryField({Key? key, required this.onSaved}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CategoryFieldState createState() => _CategoryFieldState();
|
||||
}
|
||||
|
||||
class _CategoryFieldState extends State<CategoryField> {
|
||||
String? _selectedCategory;
|
||||
Map<String, List<String>> _categoryMap = {}; // Map pour stocker les catégories et sous-catégories
|
||||
List<DropdownMenuItem<String>> _dropdownItems = []; // Liste pour stocker les éléments de menu déroulant
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadCategories(); // Charger les catégories à partir du JSON
|
||||
}
|
||||
|
||||
// Charger les catégories depuis le fichier JSON
|
||||
Future<void> _loadCategories() async {
|
||||
try {
|
||||
final String jsonString = await rootBundle.rootBundle.loadString('lib/assets/json/event_categories.json');
|
||||
final Map<String, dynamic> jsonMap = json.decode(jsonString);
|
||||
|
||||
final Map<String, List<String>> categoryMap = {};
|
||||
jsonMap['categories'].forEach((key, value) {
|
||||
categoryMap[key] = List<String>.from(value);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_categoryMap = categoryMap;
|
||||
_dropdownItems = _buildDropdownItems();
|
||||
});
|
||||
|
||||
// Ajouter un log pour vérifier si les catégories sont bien chargées
|
||||
print("Catégories chargées: $_categoryMap");
|
||||
} catch (e) {
|
||||
print("Erreur lors du chargement des catégories : $e");
|
||||
}
|
||||
}
|
||||
|
||||
// Construire les éléments du menu déroulant avec catégorisation
|
||||
List<DropdownMenuItem<String>> _buildDropdownItems() {
|
||||
List<DropdownMenuItem<String>> items = [];
|
||||
|
||||
_categoryMap.forEach((category, subcategories) {
|
||||
items.add(
|
||||
DropdownMenuItem<String>(
|
||||
enabled: false,
|
||||
child: Text(
|
||||
category,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white70,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
for (String subcategory in subcategories) {
|
||||
items.add(
|
||||
DropdownMenuItem<String>(
|
||||
value: subcategory,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: Text(
|
||||
subcategory,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Ajouter un log pour vérifier si les éléments sont bien créés
|
||||
print("Éléments créés pour le menu déroulant: ${items.length}");
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _dropdownItems.isEmpty
|
||||
? CircularProgressIndicator() // Affiche un indicateur de chargement si les éléments ne sont pas encore prêts
|
||||
: DropdownButtonFormField<String>(
|
||||
value: _selectedCategory,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Catégorie',
|
||||
labelStyle: const TextStyle(color: Colors.white70),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withOpacity(0.1),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
prefixIcon: const Icon(Icons.category, color: Colors.white70),
|
||||
),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
dropdownColor: const Color(0xFF2C2C3E),
|
||||
iconEnabledColor: Colors.white70,
|
||||
items: _dropdownItems,
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedCategory = newValue;
|
||||
});
|
||||
},
|
||||
onSaved: widget.onSaved,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
44
lib/presentation/widgets/date_picker.dart
Normal file
44
lib/presentation/widgets/date_picker.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DatePickerField extends StatelessWidget {
|
||||
final DateTime? selectedDate;
|
||||
final Function(DateTime?) onDatePicked;
|
||||
|
||||
const DatePickerField({Key? key, this.selectedDate, required this.onDatePicked}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (picked != null) {
|
||||
onDatePicked(picked);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
selectedDate == null
|
||||
? 'Sélectionnez une date'
|
||||
: '${selectedDate!.day}/${selectedDate!.month}/${selectedDate!.year}',
|
||||
style: const TextStyle(color: Colors.white70),
|
||||
),
|
||||
const Icon(Icons.calendar_today, color: Colors.white70),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
32
lib/presentation/widgets/description_field.dart
Normal file
32
lib/presentation/widgets/description_field.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DescriptionField extends StatelessWidget {
|
||||
final FormFieldSetter<String> onSaved;
|
||||
const DescriptionField({Key? key, required this.onSaved}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Description',
|
||||
labelStyle: const TextStyle(color: Colors.white70),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withOpacity(0.1),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
prefixIcon: const Icon(Icons.description, color: Colors.white70),
|
||||
),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
maxLines: 3,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer une description';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: onSaved,
|
||||
);
|
||||
}
|
||||
}
|
||||
101
lib/presentation/widgets/event_header.dart
Normal file
101
lib/presentation/widgets/event_header.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:afterwork/core/utils/date_formatter.dart';
|
||||
import 'event_status_badge.dart';
|
||||
import 'event_menu.dart';
|
||||
|
||||
class EventHeader extends StatelessWidget {
|
||||
final String userName;
|
||||
final String userLastName;
|
||||
final String? eventDate;
|
||||
final String? imageUrl;
|
||||
final String location; // Ajout du paramètre "location" pour le lieu de l'événement
|
||||
final GlobalKey menuKey;
|
||||
final BuildContext menuContext;
|
||||
|
||||
const EventHeader({
|
||||
Key? key,
|
||||
required this.userName,
|
||||
required this.userLastName,
|
||||
this.eventDate,
|
||||
this.imageUrl,
|
||||
required this.location, // Initialisation de "location"
|
||||
required this.menuKey,
|
||||
required this.menuContext,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DateTime? date;
|
||||
try {
|
||||
date = DateTime.parse(eventDate ?? '');
|
||||
} catch (e) {
|
||||
date = null;
|
||||
}
|
||||
String formattedDate = date != null ? DateFormatter.formatDate(date) : 'Date inconnue';
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors.grey.shade800,
|
||||
backgroundImage: imageUrl != null && imageUrl!.isNotEmpty
|
||||
? NetworkImage(imageUrl!)
|
||||
: const AssetImage('lib/assets/images/placeholder.png') as ImageProvider,
|
||||
radius: 22,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$userName $userLastName',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
formattedDate,
|
||||
style: const TextStyle(
|
||||
color: Colors.white54,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// Utilisation de Row pour afficher le lieu sur la même ligne
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
location.isNotEmpty ? location : 'Lieu non spécifié',
|
||||
style: const TextStyle(
|
||||
color: Colors.white60,
|
||||
fontSize: 12,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: menuKey,
|
||||
icon: const Icon(Icons.more_vert, color: Colors.white54, size: 20),
|
||||
splashRadius: 20,
|
||||
onPressed: () {
|
||||
showEventOptions(menuContext, menuKey);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
41
lib/presentation/widgets/event_image.dart
Normal file
41
lib/presentation/widgets/event_image.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EventImage extends StatelessWidget {
|
||||
final String? imageUrl;
|
||||
final double aspectRatio;
|
||||
|
||||
const EventImage({Key? key, this.imageUrl, this.aspectRatio = 16 / 9}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
child: AspectRatio(
|
||||
aspectRatio: aspectRatio,
|
||||
child: imageUrl != null && imageUrl!.isNotEmpty
|
||||
? Image.network(
|
||||
imageUrl!,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return _buildPlaceholderImage();
|
||||
},
|
||||
)
|
||||
: _buildPlaceholderImage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlaceholderImage() {
|
||||
return Container(
|
||||
color: Colors.grey[800],
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.image_not_supported,
|
||||
color: Colors.grey[400],
|
||||
size: 50,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
43
lib/presentation/widgets/event_interaction_row.dart
Normal file
43
lib/presentation/widgets/event_interaction_row.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EventInteractionRow extends StatelessWidget {
|
||||
final VoidCallback onReact;
|
||||
final VoidCallback onComment;
|
||||
final VoidCallback onShare;
|
||||
final int reactionsCount;
|
||||
final int commentsCount;
|
||||
final int sharesCount;
|
||||
|
||||
const EventInteractionRow({
|
||||
Key? key,
|
||||
required this.onReact,
|
||||
required this.onComment,
|
||||
required this.onShare,
|
||||
required this.reactionsCount,
|
||||
required this.commentsCount,
|
||||
required this.sharesCount,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildIconButton(Icons.thumb_up_alt_outlined, 'Réagir', reactionsCount, onReact),
|
||||
_buildIconButton(Icons.comment_outlined, 'Commenter', commentsCount, onComment),
|
||||
_buildIconButton(Icons.share_outlined, 'Partager', sharesCount, onShare),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton(IconData icon, String label, int count, VoidCallback onPressed) {
|
||||
return TextButton.icon(
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon, color: const Color(0xFF1DBF73), size: 18),
|
||||
label: Text(
|
||||
'$label ($count)',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@ class EventList extends StatelessWidget {
|
||||
onParticipate: () => _handleParticipate(event),
|
||||
onCloseEvent: () => _handleCloseEvent(event),
|
||||
onReopenEvent: () => _handleReopenEvent(event),
|
||||
onRemoveEvent: () => _handleRemoveEvent(event),
|
||||
status: '',
|
||||
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -55,4 +58,10 @@ class EventList extends StatelessWidget {
|
||||
void _handleReopenEvent(EventModel event) {
|
||||
print('Événement ${event.title} réouvert');
|
||||
}
|
||||
|
||||
void _handleRemoveEvent(EventModel event) {
|
||||
print('Événement ${event.title} retiré');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
85
lib/presentation/widgets/event_menu.dart
Normal file
85
lib/presentation/widgets/event_menu.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void showEventOptions(BuildContext context, GlobalKey key) {
|
||||
final RenderBox renderBox = key.currentContext!.findRenderObject() as RenderBox;
|
||||
final Offset offset = renderBox.localToGlobal(Offset.zero);
|
||||
final RelativeRect position = RelativeRect.fromLTRB(
|
||||
offset.dx,
|
||||
offset.dy,
|
||||
offset.dx + renderBox.size.width,
|
||||
offset.dy + renderBox.size.height,
|
||||
);
|
||||
|
||||
showMenu(
|
||||
context: context,
|
||||
position: position,
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
value: 'details',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline, color: Colors.blue.shade400, size: 18), // Icône plus petite et bleue
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Voir les détails',
|
||||
style: TextStyle(
|
||||
color: Colors.blue.shade700, // Texte bleu foncé
|
||||
fontWeight: FontWeight.w500, // Poids de police plus fin
|
||||
fontSize: 14, // Taille légèrement réduite
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'edit',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.edit, color: Colors.orange.shade400, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Modifier l\'événement',
|
||||
style: TextStyle(
|
||||
color: Colors.orange.shade700,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete_outline, color: Colors.red.shade400, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Supprimer l\'événement',
|
||||
style: TextStyle(
|
||||
color: Colors.red.shade700,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
elevation: 5.0, // Réduction de l'élévation pour une ombre plus subtile
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10.0), // Ajout de bordures arrondies
|
||||
side: BorderSide(color: Colors.grey.shade300), // Bordure fine et douce
|
||||
),
|
||||
color: Colors.white, // Fond blanc pur pour un contraste élégant
|
||||
).then((value) {
|
||||
// Gérer les actions en fonction de la sélection
|
||||
if (value == 'details') {
|
||||
print('Voir les détails');
|
||||
} else if (value == 'edit') {
|
||||
print('Modifier l\'événement');
|
||||
} else if (value == 'delete') {
|
||||
print('Supprimer l\'événement');
|
||||
}
|
||||
});
|
||||
}
|
||||
42
lib/presentation/widgets/event_status_badge.dart
Normal file
42
lib/presentation/widgets/event_status_badge.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EventStatusBadge extends StatelessWidget {
|
||||
final String status;
|
||||
|
||||
const EventStatusBadge({Key? key, required this.status}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||
decoration: BoxDecoration(
|
||||
color: status == 'fermé' ? Colors.red.withOpacity(0.2) : Colors.green.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
border: Border.all(
|
||||
color: status == 'fermé' ? Colors.red : Colors.green,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
status == 'fermé' ? Icons.lock : Icons.lock_open,
|
||||
color: status == 'fermé' ? Colors.red : Colors.green,
|
||||
size: 16.0,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
status == 'fermé' ? 'Fermé' : 'Ouvert',
|
||||
style: TextStyle(
|
||||
color: status == 'fermé' ? Colors.red : Colors.green,
|
||||
fontSize: 12,
|
||||
fontStyle: FontStyle.italic,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
34
lib/presentation/widgets/image_picker.dart
Normal file
34
lib/presentation/widgets/image_picker.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ImagePickerField extends StatelessWidget {
|
||||
final String? imagePath;
|
||||
final VoidCallback onImagePicked;
|
||||
|
||||
const ImagePickerField({Key? key, this.imagePath, required this.onImagePicked}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onImagePicked,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
imagePath == null
|
||||
? 'Sélectionnez une image'
|
||||
: 'Image sélectionnée: $imagePath',
|
||||
style: const TextStyle(color: Colors.white70),
|
||||
),
|
||||
const Icon(Icons.image, color: Colors.white70),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
100
lib/presentation/widgets/image_preview_picker.dart
Normal file
100
lib/presentation/widgets/image_preview_picker.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class ImagePreviewPicker extends StatefulWidget {
|
||||
final void Function(File?) onImagePicked;
|
||||
|
||||
const ImagePreviewPicker({Key? key, required this.onImagePicked}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ImagePreviewPickerState createState() => _ImagePreviewPickerState();
|
||||
}
|
||||
|
||||
class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
|
||||
File? _selectedImageFile;
|
||||
|
||||
Future<void> _pickImage() async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
|
||||
final XFile? pickedFile = await showModalBottomSheet<XFile?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.camera_alt),
|
||||
title: const Text('Take a Photo'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context, await picker.pickImage(source: ImageSource.camera));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.photo_library),
|
||||
title: const Text('Choose from Gallery'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context, await picker.pickImage(source: ImageSource.gallery));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (pickedFile != null) {
|
||||
setState(() {
|
||||
_selectedImageFile = File(pickedFile.path);
|
||||
widget.onImagePicked(_selectedImageFile); // Pass the picked image to the parent
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: _pickImage,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Aperçu de l\'image (16:9)',
|
||||
style: TextStyle(color: Colors.white70),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black26,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
border: Border.all(color: Colors.white70, width: 1),
|
||||
),
|
||||
child: _selectedImageFile != null
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
child: Image.file(
|
||||
_selectedImageFile!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Center(
|
||||
child: Icon(Icons.error, color: Colors.red),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const Center(
|
||||
child: Text(
|
||||
'Cliquez pour ajouter une image',
|
||||
style: TextStyle(color: Colors.white54),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
26
lib/presentation/widgets/link_field.dart
Normal file
26
lib/presentation/widgets/link_field.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LinkField extends StatelessWidget {
|
||||
final FormFieldSetter<String> onSaved;
|
||||
|
||||
const LinkField({Key? key, required this.onSaved}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Lien (optionnel)',
|
||||
labelStyle: const TextStyle(color: Colors.white70),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withOpacity(0.1),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
prefixIcon: const Icon(Icons.link, color: Colors.white70),
|
||||
),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
onSaved: onSaved,
|
||||
);
|
||||
}
|
||||
}
|
||||
48
lib/presentation/widgets/location_field.dart
Normal file
48
lib/presentation/widgets/location_field.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import '../screens/location/location_picker_Screen.dart';
|
||||
|
||||
class LocationField extends StatelessWidget {
|
||||
final String location;
|
||||
final LatLng? selectedLatLng;
|
||||
final Function(LatLng?) onLocationPicked;
|
||||
|
||||
const LocationField({Key? key, required this.location, this.selectedLatLng, required this.onLocationPicked}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
final LatLng? pickedLocation = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const LocationPickerScreen(),
|
||||
),
|
||||
);
|
||||
if (pickedLocation != null) {
|
||||
onLocationPicked(pickedLocation);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
selectedLatLng == null
|
||||
? 'Sélectionnez une localisation'
|
||||
: 'Localisation: $location',
|
||||
style: const TextStyle(color: Colors.white70),
|
||||
),
|
||||
const Icon(Icons.location_on, color: Colors.white70),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
54
lib/presentation/widgets/submit_button.dart
Normal file
54
lib/presentation/widgets/submit_button.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:afterwork/core/constants/colors.dart';
|
||||
|
||||
class SubmitButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const SubmitButton({Key? key, required this.onPressed}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF1DBF73), // Start of the gradient
|
||||
Color(0xFF11998E), // End of the gradient
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 8,
|
||||
offset: const Offset(2, 4), // Shadow position
|
||||
),
|
||||
],
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.transparent, // Button background is transparent to show gradient
|
||||
shadowColor: Colors.transparent, // Remove the default shadow
|
||||
padding: const EdgeInsets.symmetric(vertical: 14.0),
|
||||
minimumSize: const Size(double.infinity, 50), // Bigger button size
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Créer l\'événement',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16, // Increase font size
|
||||
fontWeight: FontWeight.bold, // Bold text
|
||||
letterSpacing: 1.2, // Spacing between letters
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
31
lib/presentation/widgets/swipe_background.dart
Normal file
31
lib/presentation/widgets/swipe_background.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SwipeBackground extends StatelessWidget {
|
||||
final Color color;
|
||||
final IconData icon;
|
||||
final String label;
|
||||
|
||||
const SwipeBackground({
|
||||
Key? key,
|
||||
required this.color,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: color,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Icon(icon, color: Colors.white),
|
||||
const SizedBox(width: 10),
|
||||
Text(label, style: const TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
31
lib/presentation/widgets/title_field.dart
Normal file
31
lib/presentation/widgets/title_field.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TitleField extends StatelessWidget {
|
||||
final FormFieldSetter<String> onSaved;
|
||||
const TitleField({Key? key, required this.onSaved}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Titre',
|
||||
labelStyle: const TextStyle(color: Colors.white70),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withOpacity(0.1),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
prefixIcon: const Icon(Icons.title, color: Colors.white70),
|
||||
),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer un titre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: onSaved,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user