Ajout de statu d'événement (bouton non indéxé sur le status pour le moment

This commit is contained in:
2025-05-28 23:10:43 +02:00
parent 50a38816d3
commit b80a6d2623
5 changed files with 765 additions and 364 deletions

View File

@ -1,6 +1,36 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
enum EventStatus {
confirmed,
canceled,
waitingForApproval,
}
String eventStatusToString(EventStatus status) {
switch (status) {
case EventStatus.confirmed:
return 'CONFIRMED';
case EventStatus.canceled:
return 'CANCELED';
case EventStatus.waitingForApproval:
default:
return 'WAITING_FOR_APPROVAL';
}
}
EventStatus eventStatusFromString(String? status) {
switch (status) {
case 'CONFIRMED':
return EventStatus.confirmed;
case 'CANCELED':
return EventStatus.canceled;
case 'WAITING_FOR_APPROVAL':
default:
return EventStatus.waitingForApproval;
}
}
class EventModel { class EventModel {
final String id; final String id;
final String name; final String name;
@ -18,6 +48,7 @@ class EventModel {
final List<DocumentReference> workforce; final List<DocumentReference> workforce;
final List<Map<String, String>> documents; final List<Map<String, String>> documents;
final List<Map<String, dynamic>> options; final List<Map<String, dynamic>> options;
final EventStatus status;
EventModel({ EventModel({
required this.id, required this.id,
@ -36,6 +67,7 @@ class EventModel {
required this.workforce, required this.workforce,
required this.documents, required this.documents,
this.options = const [], this.options = const [],
this.status = EventStatus.waitingForApproval,
}); });
factory EventModel.fromMap(Map<String, dynamic> map, String id) { factory EventModel.fromMap(Map<String, dynamic> map, String id) {
@ -49,8 +81,9 @@ class EventModel {
if (e is Map) { if (e is Map) {
return Map<String, String>.from(e as Map); return Map<String, String>.from(e as Map);
} else if (e is String) { } else if (e is String) {
final fileName = final fileName = Uri.decodeComponent(
Uri.decodeComponent(e.split('/').last.split('?').first); e.split('/').last.split('?').first,
);
return {'name': fileName, 'url': e}; return {'name': fileName, 'url': e};
} else { } else {
return {}; return {};
@ -89,6 +122,7 @@ class EventModel {
workforce: workforceRefs.whereType<DocumentReference>().toList(), workforce: workforceRefs.whereType<DocumentReference>().toList(),
documents: docs, documents: docs,
options: options, options: options,
status: eventStatusFromString(map['status'] as String?),
); );
} }
@ -110,6 +144,7 @@ class EventModel {
'workforce': workforce, 'workforce': workforce,
'documents': documents, 'documents': documents,
'options': options, 'options': options,
'status': eventStatusToString(status),
}; };
} }
} }

View File

@ -20,6 +20,8 @@ import 'package:flutter_dropzone/flutter_dropzone.dart';
import 'package:em2rp/views/widgets/inputs/dropzone_upload_widget.dart'; import 'package:em2rp/views/widgets/inputs/dropzone_upload_widget.dart';
import 'package:em2rp/views/widgets/user_management/user_multi_select_widget.dart'; import 'package:em2rp/views/widgets/user_management/user_multi_select_widget.dart';
import 'package:em2rp/views/widgets/inputs/option_selector_widget.dart'; import 'package:em2rp/views/widgets/inputs/option_selector_widget.dart';
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html;
class EventAddPage extends StatefulWidget { class EventAddPage extends StatefulWidget {
const EventAddPage({super.key}); const EventAddPage({super.key});
@ -43,6 +45,11 @@ class _EventAddPageState extends State<EventAddPage> {
String? _success; String? _success;
String? _selectedEventType; String? _selectedEventType;
final List<String> _eventTypes = ['Bal', 'Mariage', 'Anniversaire']; final List<String> _eventTypes = ['Bal', 'Mariage', 'Anniversaire'];
final Map<String, double> _eventTypeDefaultPrices = {
'Bal': 800.0,
'Mariage': 1500.0,
'Anniversaire': 500.0,
};
int _descriptionMaxLines = 3; int _descriptionMaxLines = 3;
List<String> _selectedUserIds = []; List<String> _selectedUserIds = [];
List<UserModel> _allUsers = []; List<UserModel> _allUsers = [];
@ -51,12 +58,22 @@ class _EventAddPageState extends State<EventAddPage> {
DropzoneViewController? _dropzoneController; DropzoneViewController? _dropzoneController;
bool _isDropzoneHighlighted = false; bool _isDropzoneHighlighted = false;
List<Map<String, dynamic>> _selectedOptions = []; List<Map<String, dynamic>> _selectedOptions = [];
bool _formChanged = false;
EventStatus _selectedStatus = EventStatus.waitingForApproval;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_descriptionController.addListener(_handleDescriptionChange); _descriptionController.addListener(_handleDescriptionChange);
_fetchUsers(); _fetchUsers();
_nameController.addListener(_onAnyFieldChanged);
_basePriceController.addListener(_onAnyFieldChanged);
_installationController.addListener(_onAnyFieldChanged);
_disassemblyController.addListener(_onAnyFieldChanged);
_addressController.addListener(_onAnyFieldChanged);
_descriptionController.addListener(_onAnyFieldChanged);
_addBeforeUnloadListener();
_selectedStatus = EventStatus.waitingForApproval;
} }
void _handleDescriptionChange() { void _handleDescriptionChange() {
@ -66,6 +83,14 @@ class _EventAddPageState extends State<EventAddPage> {
}); });
} }
void _onAnyFieldChanged() {
if (!_formChanged) {
setState(() {
_formChanged = true;
});
}
}
Future<void> _fetchUsers() async { Future<void> _fetchUsers() async {
final snapshot = await FirebaseFirestore.instance.collection('users').get(); final snapshot = await FirebaseFirestore.instance.collection('users').get();
setState(() { setState(() {
@ -78,10 +103,18 @@ class _EventAddPageState extends State<EventAddPage> {
void _onEventTypeChanged(String? newType) { void _onEventTypeChanged(String? newType) {
if (newType == _selectedEventType) return; if (newType == _selectedEventType) return;
final oldType = _selectedEventType;
setState(() { setState(() {
_selectedEventType = newType; _selectedEventType = newType;
if (newType != null) { if (newType != null) {
// Appliquer le prix par défaut si champ vide ou si type changé
final defaultPrice = _eventTypeDefaultPrices[newType] ?? 0.0;
if (_basePriceController.text.isEmpty ||
(_selectedEventType != null &&
_basePriceController.text ==
(_eventTypeDefaultPrices[_selectedEventType] ?? '')
.toString())) {
_basePriceController.text = defaultPrice.toStringAsFixed(2);
}
// Efface les options non compatibles // Efface les options non compatibles
final before = _selectedOptions.length; final before = _selectedOptions.length;
_selectedOptions.removeWhere((opt) { _selectedOptions.removeWhere((opt) {
@ -99,6 +132,7 @@ class _EventAddPageState extends State<EventAddPage> {
} else { } else {
_selectedOptions.clear(); _selectedOptions.clear();
} }
_onAnyFieldChanged();
}); });
} }
@ -110,9 +144,56 @@ class _EventAddPageState extends State<EventAddPage> {
_installationController.dispose(); _installationController.dispose();
_disassemblyController.dispose(); _disassemblyController.dispose();
_addressController.dispose(); _addressController.dispose();
_removeBeforeUnloadListener();
super.dispose(); super.dispose();
} }
// --- Web: beforeunload pour empêcher la fermeture sans confirmation ---
void _addBeforeUnloadListener() {
if (kIsWeb) {
html.window.onBeforeUnload.listen(_beforeUnloadHandler);
}
}
void _removeBeforeUnloadListener() {
if (kIsWeb) {
// Il n'est pas possible de retirer un listener anonyme, donc on ne fait rien ici.
// Pour une gestion plus fine, il faudrait stocker la référence du listener.
}
}
void _beforeUnloadHandler(html.Event event) {
if (_formChanged) {
event.preventDefault();
// Pour Chrome/Edge/Firefox, il faut définir returnValue
// ignore: unsafe_html
(event as dynamic).returnValue = '';
}
}
Future<bool> _onWillPop() async {
if (!_formChanged) return true;
final shouldLeave = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Quitter la page ?'),
content: const Text(
'Les modifications non enregistrées seront perdues. Voulez-vous vraiment quitter ?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Quitter'),
),
],
),
);
return shouldLeave ?? false;
}
Future<void> _pickAndUploadFiles() async { Future<void> _pickAndUploadFiles() async {
final result = await FilePicker.platform final result = await FilePicker.platform
.pickFiles(allowMultiple: true, withData: true); .pickFiles(allowMultiple: true, withData: true);
@ -227,6 +308,7 @@ class _EventAddPageState extends State<EventAddPage> {
'price': opt['price'], 'price': opt['price'],
}) })
.toList(), .toList(),
status: _selectedStatus,
); );
final docRef = await FirebaseFirestore.instance final docRef = await FirebaseFirestore.instance
.collection('events') .collection('events')
@ -298,7 +380,9 @@ class _EventAddPageState extends State<EventAddPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
return Scaffold( return WillPopScope(
onWillPop: _onWillPop,
child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Créer un événement'), title: const Text('Créer un événement'),
), ),
@ -307,10 +391,11 @@ class _EventAddPageState extends State<EventAddPage> {
child: Card( child: Card(
elevation: 6, elevation: 6,
margin: const EdgeInsets.all(24), margin: const EdgeInsets.all(24),
shape: shape: RoundedRectangleBorder(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)), borderRadius: BorderRadius.circular(18)),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 32), padding:
const EdgeInsets.symmetric(horizontal: 32, vertical: 32),
child: Form( child: Form(
key: _formKey, key: _formKey,
child: Column( child: Column(
@ -399,7 +484,8 @@ class _EventAddPageState extends State<EventAddPage> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Début', labelText: 'Début',
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
prefixIcon: const Icon(Icons.calendar_today), prefixIcon:
const Icon(Icons.calendar_today),
suffixIcon: const Icon(Icons.edit_calendar), suffixIcon: const Icon(Icons.edit_calendar),
), ),
controller: TextEditingController( controller: TextEditingController(
@ -452,7 +538,8 @@ class _EventAddPageState extends State<EventAddPage> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Fin', labelText: 'Fin',
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
prefixIcon: const Icon(Icons.calendar_today), prefixIcon:
const Icon(Icons.calendar_today),
suffixIcon: const Icon(Icons.edit_calendar), suffixIcon: const Icon(Icons.edit_calendar),
), ),
controller: TextEditingController( controller: TextEditingController(
@ -467,7 +554,8 @@ class _EventAddPageState extends State<EventAddPage> {
_endDateTime != null && _endDateTime != null &&
(_endDateTime!.isBefore( (_endDateTime!.isBefore(
_startDateTime!) || _startDateTime!) ||
_endDateTime!.isAtSameMomentAs( _endDateTime!
.isAtSameMomentAs(
_startDateTime!))) _startDateTime!)))
? 'La date de fin doit être après la date de début' ? 'La date de fin doit être après la date de début'
: null, : null,
@ -486,8 +574,8 @@ class _EventAddPageState extends State<EventAddPage> {
prefixIcon: Icon(Icons.euro), prefixIcon: Icon(Icons.euro),
hintText: '1050.50', hintText: '1050.50',
), ),
keyboardType: keyboardType: const TextInputType.numberWithOptions(
const TextInputType.numberWithOptions(decimal: true), decimal: true),
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.allow( FilteringTextInputFormatter.allow(
RegExp(r'^\d*\.?\d{0,2}')), RegExp(r'^\d*\.?\d{0,2}')),
@ -503,6 +591,7 @@ class _EventAddPageState extends State<EventAddPage> {
} }
return null; return null;
}, },
onChanged: (_) => _onAnyFieldChanged(),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
OptionSelectorWidget( OptionSelectorWidget(
@ -610,7 +699,12 @@ class _EventAddPageState extends State<EventAddPage> {
TextButton( TextButton(
onPressed: _isLoading onPressed: _isLoading
? null ? null
: () => Navigator.of(context).pop(), : () async {
final shouldLeave = await _onWillPop();
if (shouldLeave && context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text('Annuler'), child: const Text('Annuler'),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
@ -621,13 +715,29 @@ class _EventAddPageState extends State<EventAddPage> {
? const SizedBox( ? const SizedBox(
width: 20, width: 20,
height: 20, height: 20,
child: child: CircularProgressIndicator(
CircularProgressIndicator(strokeWidth: 2), strokeWidth: 2),
) )
: const Text('Créer'), : const Text('Créer'),
), ),
], ],
), ),
const SizedBox(height: 16),
Center(
child: ElevatedButton.icon(
icon: const Icon(Icons.check_circle,
color: Colors.white),
label: const Text(
'Définir cet événement comme confirmé'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
textStyle:
const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: null,
),
),
], ],
), ),
), ),
@ -635,6 +745,7 @@ class _EventAddPageState extends State<EventAddPage> {
), ),
), ),
), ),
),
); );
} }
} }

View File

@ -8,6 +8,7 @@ import 'package:em2rp/providers/event_provider.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:cloud_firestore/cloud_firestore.dart';
class EventDetails extends StatelessWidget { class EventDetails extends StatelessWidget {
final EventModel event; final EventModel event;
@ -80,6 +81,8 @@ class EventDetails extends StatelessWidget {
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Row(
children: [
SelectableText( SelectableText(
event.name, event.name,
style: Theme.of(context).textTheme.headlineMedium?.copyWith( style: Theme.of(context).textTheme.headlineMedium?.copyWith(
@ -87,6 +90,25 @@ class EventDetails extends StatelessWidget {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
const SizedBox(width: 12),
_buildStatusIcon(event.status),
],
),
if (Provider.of<LocalUserProvider>(context, listen: false)
.hasPermission('change_event_status'))
Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: _FirestoreStatusButton(
eventId: event.id,
currentStatus: event.status,
onStatusChanged: (newStatus) async {
await FirebaseFirestore.instance
.collection('events')
.doc(event.id)
.update({'status': eventStatusToString(newStatus)});
},
),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
@ -333,6 +355,34 @@ class EventDetails extends StatelessWidget {
), ),
); );
} }
Widget _buildStatusIcon(EventStatus status) {
Color color;
IconData icon;
String tooltip;
switch (status) {
case EventStatus.confirmed:
color = Colors.green;
icon = Icons.check_circle;
tooltip = 'Confirmé';
break;
case EventStatus.canceled:
color = Colors.red;
icon = Icons.cancel;
tooltip = 'Annulé';
break;
case EventStatus.waitingForApproval:
default:
color = Colors.amber;
icon = Icons.hourglass_empty;
tooltip = 'En attente de validation';
break;
}
return Tooltip(
message: tooltip,
child: Icon(icon, color: color, size: 28),
);
}
} }
class EventAddDialog extends StatefulWidget { class EventAddDialog extends StatefulWidget {
@ -573,3 +623,134 @@ class _EventAddDialogState extends State<EventAddDialog> {
); );
} }
} }
class _FirestoreStatusButton extends StatefulWidget {
final String eventId;
final EventStatus currentStatus;
final Future<void> Function(EventStatus) onStatusChanged;
const _FirestoreStatusButton(
{required this.eventId,
required this.currentStatus,
required this.onStatusChanged});
@override
State<_FirestoreStatusButton> createState() => _FirestoreStatusButtonState();
}
class _FirestoreStatusButtonState extends State<_FirestoreStatusButton> {
late EventStatus _status;
bool _loading = false;
@override
void initState() {
super.initState();
_status = widget.currentStatus;
}
Future<void> changerStatut(EventStatus nouveau) async {
if (_status == nouveau) return;
setState(() => _loading = true);
await FirebaseFirestore.instance
.collection('events')
.doc(widget.eventId)
.update({'status': eventStatusToString(nouveau)});
setState(() {
_status = nouveau;
_loading = false;
});
}
@override
Widget build(BuildContext context) {
String texte;
Color couleurFond;
List<Widget> enfants = [];
switch (_status) {
case EventStatus.waitingForApproval:
texte = "En Attente";
couleurFond = Colors.yellow.shade600;
enfants = [
_buildIconButton(Icons.close, Colors.red,
() => changerStatut(EventStatus.canceled)),
_buildLabel(texte, couleurFond),
_buildIconButton(Icons.check, Colors.green,
() => changerStatut(EventStatus.confirmed)),
];
break;
case EventStatus.confirmed:
texte = "Confirmé";
couleurFond = Colors.green;
enfants = [
_buildIconButton(Icons.close, Colors.red,
() => changerStatut(EventStatus.canceled)),
_buildIconButton(Icons.hourglass_empty, Colors.yellow.shade700,
() => changerStatut(EventStatus.waitingForApproval)),
_buildLabel(texte, couleurFond),
];
break;
case EventStatus.canceled:
texte = "Annulé";
couleurFond = Colors.red;
enfants = [
_buildLabel(texte, couleurFond),
_buildIconButton(Icons.hourglass_empty, Colors.yellow.shade700,
() => changerStatut(EventStatus.waitingForApproval)),
_buildIconButton(Icons.check, Colors.green,
() => changerStatut(EventStatus.confirmed)),
];
break;
}
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.all(2),
decoration: const BoxDecoration(
color: Colors.transparent,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: enfants,
),
);
}
Widget _buildLabel(String texte, Color couleur) {
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
margin: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: couleur,
borderRadius: BorderRadius.circular(6),
),
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: Text(
texte,
key: ValueKey(texte),
style: const TextStyle(
fontWeight: FontWeight.bold, color: Colors.white, fontSize: 13),
),
),
);
}
Widget _buildIconButton(
IconData icone, Color couleur, VoidCallback onPressed) {
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
margin: const EdgeInsets.symmetric(horizontal: 2),
decoration: BoxDecoration(
border: Border.all(color: couleur, width: 1.5),
borderRadius: BorderRadius.circular(6),
),
child: IconButton(
icon: Icon(icone, color: couleur, size: 16),
onPressed: _loading ? null : onPressed,
splashRadius: 16,
tooltip: 'Changer statut',
padding: const EdgeInsets.all(4),
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
),
);
}
}

View File

@ -213,6 +213,27 @@ class MonthView extends StatelessWidget {
Widget _buildEventItem( Widget _buildEventItem(
EventModel event, bool isSelected, DateTime currentDay) { EventModel event, bool isSelected, DateTime currentDay) {
Color color;
Color textColor;
IconData icon;
switch (event.status) {
case EventStatus.confirmed:
color = Colors.green;
textColor = Colors.white;
icon = Icons.check;
break;
case EventStatus.canceled:
color = Colors.red;
textColor = Colors.white;
icon = Icons.close;
break;
case EventStatus.waitingForApproval:
default:
color = Colors.amber;
textColor = Colors.black;
icon = Icons.hourglass_empty;
break;
}
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
onDaySelected(currentDay, currentDay); onDaySelected(currentDay, currentDay);
@ -222,11 +243,15 @@ class MonthView extends StatelessWidget {
margin: const EdgeInsets.only(bottom: 2), margin: const EdgeInsets.only(bottom: 2),
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected color: isSelected ? color.withAlpha(220) : color.withOpacity(0.18),
? Colors.white.withAlpha(51)
: AppColors.rouge.withAlpha(26),
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
), ),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(icon, color: textColor, size: 16),
const SizedBox(width: 4),
Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -234,7 +259,7 @@ class MonthView extends StatelessWidget {
event.name, event.name,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
color: isSelected ? Colors.white : AppColors.rouge, color: textColor,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
maxLines: 1, maxLines: 1,
@ -242,16 +267,19 @@ class MonthView extends StatelessWidget {
), ),
if (CalendarUtils.isMultiDayEvent(event)) if (CalendarUtils.isMultiDayEvent(event))
Text( Text(
'Jour ${CalendarUtils.calculateDayNumber(event.startDateTime, event.startDateTime)}/${CalendarUtils.calculateTotalDays(event)}', 'Jour ${CalendarUtils.calculateDayNumber(event.startDateTime, currentDay)}/${CalendarUtils.calculateTotalDays(event)}',
style: TextStyle( style: TextStyle(
fontSize: 10, fontSize: 10,
color: isSelected ? Colors.white : AppColors.rouge, color: textColor,
), ),
maxLines: 1, maxLines: 1,
), ),
], ],
), ),
), ),
],
),
),
); );
} }
} }

View File

@ -272,21 +272,29 @@ class WeekView extends StatelessWidget {
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(4),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected color: isSelected
? AppColors.rouge.withAlpha(80) ? _getStatusColor(e.event.status).withAlpha(220)
: AppColors.rouge.withAlpha(26), : _getStatusColor(e.event.status).withOpacity(0.18),
border: Border.all( border: Border.all(
color: AppColors.rouge, color: _getStatusColor(e.event.status),
width: isSelected ? 3 : 1, width: isSelected ? 3 : 1,
), ),
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
), ),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(_getStatusIcon(e.event.status),
color: _getStatusTextColor(e.event.status),
size: 16),
const SizedBox(width: 4),
Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
e.event.name, e.event.name,
style: const TextStyle( style: TextStyle(
color: AppColors.rouge, color: _getStatusTextColor(e.event.status),
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@ -296,8 +304,8 @@ class WeekView extends StatelessWidget {
if (CalendarUtils.isMultiDayEvent(e.event)) if (CalendarUtils.isMultiDayEvent(e.event))
Text( Text(
'Jour ${CalendarUtils.calculateDayNumber(e.event.startDateTime, weekStart.add(Duration(days: dayIdx)))}/${CalendarUtils.calculateTotalDays(e.event)}', 'Jour ${CalendarUtils.calculateDayNumber(e.event.startDateTime, weekStart.add(Duration(days: dayIdx)))}/${CalendarUtils.calculateTotalDays(e.event)}',
style: const TextStyle( style: TextStyle(
color: AppColors.rouge, color: _getStatusTextColor(e.event.status),
fontSize: 10, fontSize: 10,
), ),
maxLines: 1, maxLines: 1,
@ -305,6 +313,9 @@ class WeekView extends StatelessWidget {
], ],
), ),
), ),
],
),
),
), ),
); );
}).toList(), }).toList(),
@ -377,6 +388,41 @@ class WeekView extends StatelessWidget {
bool _overlap(_PositionedEvent a, _PositionedEvent b) { bool _overlap(_PositionedEvent a, _PositionedEvent b) {
return a.end.isAfter(b.start) && a.start.isBefore(b.end); return a.end.isAfter(b.start) && a.start.isBefore(b.end);
} }
Color _getStatusColor(EventStatus status) {
switch (status) {
case EventStatus.confirmed:
return Colors.green;
case EventStatus.canceled:
return Colors.red;
case EventStatus.waitingForApproval:
default:
return Colors.amber;
}
}
Color _getStatusTextColor(EventStatus status) {
switch (status) {
case EventStatus.confirmed:
case EventStatus.canceled:
return Colors.white;
case EventStatus.waitingForApproval:
default:
return Colors.black;
}
}
IconData _getStatusIcon(EventStatus status) {
switch (status) {
case EventStatus.confirmed:
return Icons.check;
case EventStatus.canceled:
return Icons.close;
case EventStatus.waitingForApproval:
default:
return Icons.hourglass_empty;
}
}
} }
class _PositionedEvent { class _PositionedEvent {