Refactoring + Version améliorée

This commit is contained in:
DahoudG
2024-09-25 21:28:04 +00:00
parent 6b12cfeb41
commit 8e625c1080
28 changed files with 1113 additions and 261 deletions

View 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,
);
}
}

View 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),
],
),
),
);
}
}

View 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,
);
}
}

View 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);
},
),
],
);
}
}

View 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,
),
),
);
}
}

View 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),
),
);
}
}

View File

@@ -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é');
}
}

View 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');
}
});
}

View 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,
),
),
],
),
);
}
}

View 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),
],
),
),
);
}
}

View 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),
),
),
),
),
],
),
);
}
}

View 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,
);
}
}

View 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),
],
),
),
);
}
}

View 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
),
),
),
);
}
}

View 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)),
],
),
);
}
}

View 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,
);
}
}