feat: Refactor group deletion logic to use tripId and add reset trips functionality
This commit is contained in:
@@ -19,21 +19,25 @@ class HomeContent extends StatefulWidget {
|
||||
class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
bool _hasLoadedTrips = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// MODIFIÉ : Attendre un frame avant de charger
|
||||
// MODIFIÉ : Utiliser addPostFrameCallback pour attendre que le widget tree soit prêt
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadTripsIfUserLoaded();
|
||||
});
|
||||
}
|
||||
|
||||
void _loadTripsIfUserLoaded() {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is UserLoaded) {
|
||||
print('🚀 Chargement initial des trips pour ${userState.user.id}');
|
||||
context.read<TripBloc>().add(LoadTripsByUserId(userId: userState.user.id));
|
||||
if (!_hasLoadedTrips && mounted) {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is UserLoaded) {
|
||||
_hasLoadedTrips = true;
|
||||
context.read<TripBloc>().add(LoadTripsByUserId(userId: userState.user.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +97,6 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
),
|
||||
);
|
||||
} else if (tripState is TripCreated) {
|
||||
// Afficher un message de succès temporaire
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage en cours de création...'),
|
||||
@@ -104,12 +107,17 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
}
|
||||
},
|
||||
builder: (context, tripState) {
|
||||
// AJOUTÉ : Si l'état est initial et qu'on n'a pas encore chargé, charger maintenant
|
||||
if (tripState is TripInitial && !_hasLoadedTrips) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadTripsIfUserLoaded();
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
print('🔄 Pull to refresh');
|
||||
context.read<TripBloc>().add(LoadTripsByUserId(userId: user.id));
|
||||
// Attendre que le chargement soit terminé
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
@@ -137,6 +145,8 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
tripState.trips.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildTripsList(tripState.trips)
|
||||
else if (tripState is TripInitial)
|
||||
_buildLoadingState() // Afficher le loader pendant le premier chargement
|
||||
else
|
||||
_buildEmptyState(),
|
||||
|
||||
@@ -152,9 +162,7 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
MaterialPageRoute(builder: (context) => const CreateTripContent()),
|
||||
);
|
||||
|
||||
// AJOUTÉ : Recharger manuellement après retour
|
||||
if (result == true && mounted) {
|
||||
print('🔄 Retour de création, rechargement...');
|
||||
context.read<TripBloc>().add(LoadTripsByUserId(userId: user.id));
|
||||
}
|
||||
},
|
||||
@@ -251,7 +259,6 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
// AJOUTÉ : Recharger après retour des détails
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@@ -262,7 +269,6 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
if (result == true && mounted) {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is UserLoaded) {
|
||||
print('🔄 Retour des détails, rechargement...');
|
||||
context.read<TripBloc>().add(LoadTripsByUserId(userId: userState.user.id));
|
||||
}
|
||||
}
|
||||
@@ -304,7 +310,7 @@ class _HomeContentState extends State<HomeContent> with AutomaticKeepAliveClient
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(trip).withOpacity(0.2),
|
||||
color: _getStatusColor(trip).withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
|
||||
Reference in New Issue
Block a user