feat(frontend): Séparation des demandes d'amitié envoyées et reçues
- Ajout de deux endpoints distincts dans Urls: getSentFriendRequestsWithUserId et getReceivedFriendRequestsWithUserId - Ajout de méthodes dans FriendsRepository et FriendsRepositoryImpl pour récupérer séparément les demandes envoyées et reçues - Ajout de la méthode cancelFriendRequest pour annuler une demande envoyée - Modification de FriendsProvider pour gérer deux listes distinctes: sentRequests et receivedRequests - Mise à jour de FriendsScreen pour afficher deux sections: - Demandes reçues: avec boutons Accepter/Rejeter - Demandes envoyées: avec bouton Annuler uniquement - Correction du mapping JSON dans FriendRequest.fromJson (userNom/userPrenoms correctement mappés) - Amélioration de FriendRequestCard pour gérer les deux types de demandes - Correction de la validation d'URL d'image dans FriendDetailScreen - Support du champ uuid dans UserModel.fromJson pour compatibilité backend
This commit is contained in:
@@ -1,176 +1,247 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../data/providers/friends_provider.dart';
|
||||
import '../../../domain/entities/friend.dart';
|
||||
import '../../widgets/friend_detail_screen.dart';
|
||||
import '../../../domain/entities/friend_request.dart';
|
||||
import '../../widgets/add_friend_dialog.dart';
|
||||
import '../../widgets/cards/friend_card.dart';
|
||||
import '../../widgets/friend_request_card.dart';
|
||||
import '../../widgets/search_friends.dart';
|
||||
|
||||
/// [FriendsScreen] est l'écran principal permettant d'afficher et de gérer la liste des amis.
|
||||
/// Il inclut des fonctionnalités de pagination, de recherche, et de rafraîchissement manuel de la liste.
|
||||
/// Ce widget est un [StatefulWidget] afin de pouvoir mettre à jour dynamiquement la liste des amis.
|
||||
/// Écran principal pour afficher et gérer la liste des amis.
|
||||
///
|
||||
/// Cet écran inclut des fonctionnalités de pagination, de recherche,
|
||||
/// et de rafraîchissement manuel de la liste avec design moderne et compact.
|
||||
///
|
||||
/// **Fonctionnalités:**
|
||||
/// - Affichage de la liste des amis en grille
|
||||
/// - Recherche d'amis
|
||||
/// - Pagination automatique
|
||||
/// - Pull-to-refresh
|
||||
/// - Ajout d'amis
|
||||
class FriendsScreen extends StatefulWidget {
|
||||
final String userId; // Identifiant de l'utilisateur pour récupérer ses amis
|
||||
const FriendsScreen({required this.userId, super.key});
|
||||
|
||||
const FriendsScreen({Key? key, required this.userId}) : super(key: key);
|
||||
final String userId;
|
||||
|
||||
@override
|
||||
_FriendsScreenState createState() => _FriendsScreenState();
|
||||
State<FriendsScreen> createState() => _FriendsScreenState();
|
||||
}
|
||||
|
||||
class _FriendsScreenState extends State<FriendsScreen> {
|
||||
class _FriendsScreenState extends State<FriendsScreen> with SingleTickerProviderStateMixin {
|
||||
// ============================================================================
|
||||
// CONTROLLERS
|
||||
// ============================================================================
|
||||
|
||||
late ScrollController _scrollController;
|
||||
late TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialisation du contrôleur de défilement pour la gestion de la pagination.
|
||||
_initializeScrollController();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
_loadFriends();
|
||||
_loadSentRequests();
|
||||
_loadReceivedRequests();
|
||||
}
|
||||
|
||||
void _initializeScrollController() {
|
||||
_scrollController = ScrollController();
|
||||
_scrollController.addListener(_onScroll);
|
||||
|
||||
// Log pour indiquer le début du chargement des amis
|
||||
debugPrint("[LOG] Initialisation de la page : chargement des amis pour l'utilisateur ${widget.userId}");
|
||||
// Chargement initial de la liste d'amis via le fournisseur (Provider)
|
||||
Provider.of<FriendsProvider>(context, listen: false).fetchFriends(widget.userId);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Nettoyage du contrôleur de défilement pour éviter les fuites de mémoire.
|
||||
_scrollController.removeListener(_onScroll);
|
||||
_scrollController.dispose();
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
debugPrint("[LOG] Dispose : contrôleur de défilement supprimé");
|
||||
}
|
||||
|
||||
/// Méthode déclenchée lors du défilement de la liste.
|
||||
/// Vérifie si l'utilisateur a atteint le bas de la liste pour charger plus d'amis.
|
||||
// ============================================================================
|
||||
// ACTIONS
|
||||
// ============================================================================
|
||||
|
||||
/// Charge les amis au démarrage.
|
||||
void _loadFriends() {
|
||||
Provider.of<FriendsProvider>(context, listen: false)
|
||||
.fetchFriends(widget.userId);
|
||||
}
|
||||
|
||||
/// Charge les demandes envoyées au démarrage.
|
||||
void _loadSentRequests() {
|
||||
Provider.of<FriendsProvider>(context, listen: false)
|
||||
.fetchSentRequests();
|
||||
}
|
||||
|
||||
/// Charge les demandes reçues au démarrage.
|
||||
void _loadReceivedRequests() {
|
||||
Provider.of<FriendsProvider>(context, listen: false)
|
||||
.fetchReceivedRequests();
|
||||
}
|
||||
|
||||
/// Gère le défilement pour la pagination.
|
||||
void _onScroll() {
|
||||
final provider = Provider.of<FriendsProvider>(context, listen: false);
|
||||
|
||||
// Ajout d'une marge de 200 pixels pour détecter le bas de la liste plus tôt.
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 200 &&
|
||||
!provider.isLoading && provider.hasMore) {
|
||||
debugPrint("[LOG] Scroll : Fin de liste atteinte, chargement de la page suivante.");
|
||||
provider.fetchFriends(widget.userId, loadMore: true); // Chargement de plus d'amis
|
||||
_scrollController.position.maxScrollExtent - 200 &&
|
||||
!provider.isLoading &&
|
||||
provider.hasMore) {
|
||||
provider.fetchFriends(widget.userId, loadMore: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gère le rafraîchissement.
|
||||
Future<void> _handleRefresh() async {
|
||||
final provider = Provider.of<FriendsProvider>(context, listen: false);
|
||||
provider.fetchFriends(widget.userId);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
|
||||
/// Gère l'ajout d'un ami.
|
||||
void _handleAddFriend() {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AddFriendDialog(
|
||||
onFriendAdded: () {
|
||||
// Rafraîchir la liste des amis et des demandes après l'ajout
|
||||
_loadFriends();
|
||||
_loadSentRequests();
|
||||
_loadReceivedRequests();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// BUILD
|
||||
// ============================================================================
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Accès au fournisseur pour gérer les données et les états des amis.
|
||||
final friendsProvider = Provider.of<FriendsProvider>(context, listen: false);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Mes Amis'),
|
||||
actions: [
|
||||
// Bouton pour rafraîchir la liste des amis
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () {
|
||||
// Vérifie si la liste n'est pas en cours de chargement avant d'envoyer une nouvelle requête.
|
||||
if (!friendsProvider.isLoading) {
|
||||
debugPrint("[LOG] Bouton Refresh : demande de rafraîchissement de la liste des amis");
|
||||
friendsProvider.fetchFriends(widget.userId);
|
||||
} else {
|
||||
debugPrint("[LOG] Rafraîchissement en cours, action ignorée.");
|
||||
}
|
||||
},
|
||||
appBar: _buildAppBar(theme),
|
||||
body: _buildBody(theme),
|
||||
floatingActionButton: _buildFloatingActionButton(theme),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit la barre d'application.
|
||||
PreferredSizeWidget _buildAppBar(ThemeData theme) {
|
||||
return AppBar(
|
||||
title: const Text('Mes Amis'),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: const [
|
||||
Tab(text: 'Amis', icon: Icon(Icons.people)),
|
||||
Tab(text: 'Demandes', icon: Icon(Icons.person_add)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: 'Actualiser',
|
||||
onPressed: () {
|
||||
_loadFriends();
|
||||
_loadSentRequests();
|
||||
_loadReceivedRequests();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit le corps de l'écran.
|
||||
Widget _buildBody(ThemeData theme) {
|
||||
return SafeArea(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
// Onglet Amis
|
||||
Column(
|
||||
children: [
|
||||
_buildSearchBar(),
|
||||
Expanded(
|
||||
child: Consumer<FriendsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
if (provider.isLoading && provider.friendsList.isEmpty) {
|
||||
return _buildLoadingState(theme);
|
||||
}
|
||||
|
||||
if (provider.friendsList.isEmpty) {
|
||||
return _buildEmptyState(theme);
|
||||
}
|
||||
|
||||
return _buildFriendsList(theme, provider);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Onglet Demandes en attente
|
||||
_buildPendingRequestsTab(theme),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit la barre de recherche.
|
||||
Widget _buildSearchBar() {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: SearchFriends(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit l'état de chargement.
|
||||
Widget _buildLoadingState(ThemeData theme) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Chargement des amis...',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit l'état vide.
|
||||
Widget _buildEmptyState(ThemeData theme) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Widget de recherche d'amis en haut de l'écran
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: SearchFriends(),
|
||||
Icon(
|
||||
Icons.people_outline,
|
||||
size: 64,
|
||||
color: theme.colorScheme.secondary.withOpacity(0.6),
|
||||
),
|
||||
Expanded(
|
||||
// Construction de la liste d'amis avec un affichage en grille
|
||||
child: Consumer<FriendsProvider>(
|
||||
builder: (context, friendsProvider, child) {
|
||||
// Si le chargement est en cours et qu'il n'y a aucun ami, afficher un indicateur de chargement.
|
||||
if (friendsProvider.isLoading && friendsProvider.friendsList.isEmpty) {
|
||||
debugPrint("[LOG] Chargement : affichage de l'indicateur de progression");
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
// Si la liste est vide après le chargement, afficher un message indiquant qu'aucun ami n'a été trouvé.
|
||||
if (friendsProvider.friendsList.isEmpty) {
|
||||
debugPrint("[LOG] Liste vide : Aucun ami trouvé");
|
||||
return const Center(
|
||||
child: Text('Aucun ami trouvé'),
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
controller: _scrollController, // Utilisation du contrôleur pour la pagination
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2, // Deux amis par ligne
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
childAspectRatio: 0.8, // Ajuste la taille des cartes
|
||||
),
|
||||
itemCount: friendsProvider.friendsList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final friend = friendsProvider.friendsList[index];
|
||||
// Affichage de chaque ami dans une carte avec une animation
|
||||
return GestureDetector(
|
||||
onTap: () => _navigateToFriendDetail(context, friend), // Action au clic sur l'avatar
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
transform: Matrix4.identity()
|
||||
..scale(1.05), // Effet de zoom lors du survol
|
||||
child: Card(
|
||||
elevation: 6,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundImage: friend.imageUrl != null && friend.imageUrl!.isNotEmpty
|
||||
? (friend.imageUrl!.startsWith('https') // Vérifie si l'image est une URL réseau.
|
||||
? NetworkImage(friend.imageUrl!) // Charge l'image depuis une URL réseau.
|
||||
: AssetImage(friend.imageUrl!) as ImageProvider) // Sinon, charge depuis les ressources locales.
|
||||
: const AssetImage('lib/assets/images/default_avatar.png'), // Si aucune image, utilise l'image par défaut.
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"${friend.friendFirstName} ${friend.friendLastName}",
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
friend.status.name,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
friend.lastInteraction ?? 'Aucune interaction récente',
|
||||
style: const TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Aucun ami trouvé',
|
||||
style: theme.textTheme.titleLarge,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Commencez à ajouter des amis pour voir leurs événements',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -178,23 +249,226 @@ class _FriendsScreenState extends State<FriendsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Navigation vers l'écran de détails de l'ami
|
||||
/// Permet de voir les informations complètes d'un ami lorsque l'utilisateur clique sur son avatar.
|
||||
void _navigateToFriendDetail(BuildContext context, Friend friend) {
|
||||
debugPrint("[LOG] Navigation : Détails de l'ami ${friend.friendFirstName} ${friend.friendLastName}");
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FriendDetailScreen(
|
||||
friendFirstName: friend.friendFirstName, // Prénom de l'ami
|
||||
friendLastName: friend.friendLastName, // Nom de l'ami
|
||||
imageUrl: friend.imageUrl ?? '', // URL de l'image de l'ami (ou valeur par défaut)
|
||||
friendId: friend.friendId, // Identifiant unique de l'ami
|
||||
status: friend.status, // Statut de l'ami
|
||||
lastInteraction: friend.lastInteraction ?? 'Aucune', // Dernière interaction (si disponible)
|
||||
dateAdded: friend.dateAdded ?? 'Inconnu', // Date d'ajout de l'ami (si disponible)
|
||||
/// Construit la liste des amis.
|
||||
Widget _buildFriendsList(ThemeData theme, FriendsProvider provider) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
color: theme.colorScheme.primary,
|
||||
child: GridView.builder(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 16,
|
||||
childAspectRatio: 0.75,
|
||||
),
|
||||
itemCount: provider.friendsList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final friend = provider.friendsList[index];
|
||||
return FriendCard(friend: friend);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit le bouton flottant (compact).
|
||||
Widget _buildFloatingActionButton(ThemeData theme) {
|
||||
return FloatingActionButton(
|
||||
onPressed: _handleAddFriend,
|
||||
tooltip: 'Ajouter un ami',
|
||||
child: const Icon(Icons.person_add),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit l'onglet des demandes en attente avec deux sections.
|
||||
Widget _buildPendingRequestsTab(ThemeData theme) {
|
||||
return Consumer<FriendsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
final isLoading = provider.isLoadingReceivedRequests || provider.isLoadingSentRequests;
|
||||
final hasReceived = provider.receivedRequests.isNotEmpty;
|
||||
final hasSent = provider.sentRequests.isNotEmpty;
|
||||
|
||||
if (isLoading && !hasReceived && !hasSent) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Chargement des demandes...',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasReceived && !hasSent) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.person_add_disabled,
|
||||
size: 64,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucune demande en attente',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Les demandes d\'amitié apparaîtront ici',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await Future.wait([
|
||||
provider.fetchReceivedRequests(),
|
||||
provider.fetchSentRequests(),
|
||||
]);
|
||||
},
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
// Section Demandes reçues
|
||||
if (hasReceived) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
'Demandes reçues',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
...provider.receivedRequests.map((request) => FriendRequestCard(
|
||||
request: request,
|
||||
onAccept: () => _handleAcceptRequest(provider, request.friendshipId),
|
||||
onReject: () => _handleRejectRequest(provider, request.friendshipId),
|
||||
)),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
// Section Demandes envoyées
|
||||
if (hasSent) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
'Demandes envoyées',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
...provider.sentRequests.map((request) => FriendRequestCard(
|
||||
request: request,
|
||||
onAccept: null, // Pas d'accepter pour les demandes envoyées
|
||||
onReject: () => _handleCancelRequest(provider, request.friendshipId),
|
||||
isSentRequest: true, // Indique que c'est une demande envoyée
|
||||
)),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Gère l'acceptation d'une demande d'amitié.
|
||||
Future<void> _handleAcceptRequest(FriendsProvider provider, String friendshipId) async {
|
||||
try {
|
||||
await provider.acceptFriendRequest(friendshipId);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Demande d\'amitié acceptée'),
|
||||
backgroundColor: Colors.green,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
// Rafraîchir les deux onglets
|
||||
_loadFriends();
|
||||
_loadReceivedRequests();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: ${e.toString()}'),
|
||||
backgroundColor: Colors.red,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gère le rejet d'une demande d'amitié.
|
||||
Future<void> _handleRejectRequest(FriendsProvider provider, String friendshipId) async {
|
||||
try {
|
||||
await provider.rejectFriendRequest(friendshipId);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Demande d\'amitié rejetée'),
|
||||
backgroundColor: Colors.orange,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
_loadReceivedRequests();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: ${e.toString()}'),
|
||||
backgroundColor: Colors.red,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gère l'annulation d'une demande d'amitié envoyée.
|
||||
Future<void> _handleCancelRequest(FriendsProvider provider, String friendshipId) async {
|
||||
try {
|
||||
await provider.cancelFriendRequest(friendshipId);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Demande d\'amitié annulée'),
|
||||
backgroundColor: Colors.blue,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
_loadSentRequests();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: ${e.toString()}'),
|
||||
backgroundColor: Colors.red,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user