Ajout de statu d'événement (bouton non indéxé sur le status pour le moment
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:em2rp/providers/event_provider.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class EventDetails extends StatelessWidget {
|
||||
final EventModel event;
|
||||
@ -80,13 +81,34 @@ class EventDetails extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SelectableText(
|
||||
event.name,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: AppColors.noir,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SelectableText(
|
||||
event.name,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: AppColors.noir,
|
||||
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),
|
||||
Expanded(
|
||||
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 {
|
||||
@ -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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user