Refactoring + Version améliorée
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user