feat: Refactor account handling and improve group creation logic
This commit is contained in:
@@ -9,7 +9,6 @@ import '../../blocs/trip/trip_event.dart';
|
||||
import '../../blocs/trip/trip_state.dart';
|
||||
import '../../blocs/group/group_bloc.dart';
|
||||
import '../../blocs/group/group_event.dart';
|
||||
import '../../blocs/group/group_state.dart';
|
||||
import '../../blocs/account/account_bloc.dart';
|
||||
import '../../blocs/account/account_event.dart';
|
||||
import '../../models/account.dart';
|
||||
@@ -111,15 +110,13 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocListener(
|
||||
listeners: [
|
||||
// Listener pour TripBloc
|
||||
BlocListener<TripBloc, TripState>(
|
||||
return BlocListener<TripBloc, TripState>(
|
||||
listener: (context, tripState) {
|
||||
if (tripState is TripCreated) {
|
||||
// Stocker l'ID du trip et créer le groupe
|
||||
_createdTripId = tripState.tripId;
|
||||
_createGroupForTrip(tripState.tripId);
|
||||
_createGroupForTrip(_createdTripId!);
|
||||
_createAccountForTrip(_createdTripId!);
|
||||
} else if (tripState is TripOperationSuccess) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -147,31 +144,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
// Nouveau listener pour GroupBloc
|
||||
BlocListener<GroupBloc, GroupState>(
|
||||
listener: (context, groupState) {
|
||||
if (groupState is GroupCreated && _createdTripId != null) {
|
||||
// Le groupe a été créé, maintenant créer le compte
|
||||
print('++++++++++++++ Creating account for trip ${_createdTripId!} and group ${groupState.groupId} ++++++++++++++');
|
||||
_createAccountForTrip(_createdTripId!, groupState.groupId);
|
||||
} else if (groupState is GroupError) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur lors de la création du groupe: ${groupState.message}'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
child: BlocBuilder<UserBloc, user_state.UserState>(
|
||||
child: BlocBuilder<UserBloc, user_state.UserState>(
|
||||
builder: (context, userState) {
|
||||
if (userState is! user_state.UserLoaded) {
|
||||
return Scaffold(
|
||||
@@ -661,18 +634,15 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _createAccountForTrip(String tripId, String groupId) async {
|
||||
Future<void> _createAccountForTrip(String tripId) async {
|
||||
final accountBloc = context.read<AccountBloc>();
|
||||
try {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is! user_state.UserLoaded) return;
|
||||
|
||||
print('Creating account for trip $tripId and group $groupId');
|
||||
|
||||
final account = Account(
|
||||
id: '',
|
||||
tripId: tripId,
|
||||
groupId: groupId,
|
||||
name: _titleController.text.trim(),
|
||||
);
|
||||
|
||||
@@ -683,8 +653,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
members: accountsMembers,
|
||||
));
|
||||
|
||||
print('++++++++++++++ Created account for trip $tripId and group $groupId ++++++++++++++');
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
||||
Reference in New Issue
Block a user