/// Page liste des conversations library conversations_page; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../core/di/injection_container.dart'; import '../../../../shared/design_system/unionflow_design_system.dart'; import '../../../../shared/utils/snackbar_helper.dart'; import '../bloc/messaging_bloc.dart'; import '../bloc/messaging_event.dart'; import '../bloc/messaging_state.dart'; import '../widgets/conversation_tile.dart'; class ConversationsPage extends StatelessWidget { final String? organizationId; const ConversationsPage({ super.key, this.organizationId, }); @override Widget build(BuildContext context) { return BlocProvider( create: (_) => sl() ..add(LoadConversations(organizationId: organizationId)), child: Scaffold( backgroundColor: ColorTokens.background, appBar: const UFAppBar( title: 'MESSAGES', automaticallyImplyLeading: true, ), body: BlocBuilder( builder: (context, state) { if (state is MessagingLoading) { return const Center(child: CircularProgressIndicator()); } if (state is MessagingError) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon( Icons.error_outline, size: 64, color: AppColors.error, ), const SizedBox(height: SpacingTokens.md), Text( 'Erreur', style: AppTypography.headerSmall, ), const SizedBox(height: SpacingTokens.sm), Text( state.message, style: AppTypography.bodyTextSmall, textAlign: TextAlign.center, ), const SizedBox(height: SpacingTokens.lg), UFPrimaryButton( label: 'Réessayer', onPressed: () { context.read().add( LoadConversations(organizationId: organizationId), ); }, ), ], ), ); } if (state is ConversationsLoaded) { final conversations = state.conversations; if (conversations.isEmpty) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon( Icons.chat_bubble_outline, size: 64, color: AppColors.textSecondaryLight, ), const SizedBox(height: SpacingTokens.md), Text( 'Aucune conversation', style: AppTypography.headerSmall.copyWith( color: AppColors.textSecondaryLight, ), ), const SizedBox(height: SpacingTokens.sm), Text( 'Commencez une nouvelle conversation', style: AppTypography.bodyTextSmall.copyWith( color: AppColors.textSecondaryLight, ), ), ], ), ); } return RefreshIndicator( onRefresh: () async { context.read().add( LoadConversations(organizationId: organizationId), ); }, child: ListView.separated( padding: const EdgeInsets.all(SpacingTokens.md), itemCount: conversations.length, separatorBuilder: (_, __) => const SizedBox(height: SpacingTokens.sm), itemBuilder: (context, index) { final conversation = conversations[index]; return ConversationTile( conversation: conversation, onTap: () { SnackbarHelper.showNotImplemented( context, 'Affichage des messages', ); }, ); }, ), ); } return const SizedBox.shrink(); }, ), floatingActionButton: FloatingActionButton( backgroundColor: AppColors.primaryGreen, onPressed: () { SnackbarHelper.showNotImplemented(context, 'Nouvelle conversation'); }, child: const Icon(Icons.add, color: Colors.white), ), ), ); } }