94 lines
3.9 KiB
Dart
94 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../../assets/animations/friend_expanding_card.dart';
|
|
import '../../../data/providers/friends_provider.dart';
|
|
import '../../../domain/entities/friend.dart';
|
|
import '../../widgets/friend_detail_screen.dart';
|
|
import '../../widgets/friends_appbar.dart';
|
|
import '../../widgets/search_friends.dart';
|
|
|
|
/// [FriendsScreenWithProvider] est un écran qui affiche la liste des amis.
|
|
/// Il utilise le provider [FriendsProvider] pour gérer les états et les données.
|
|
/// Chaque action est loguée pour permettre une traçabilité complète.
|
|
class FriendsScreenWithProvider extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
appBar: FriendsAppBar(),
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
const Padding(
|
|
padding: EdgeInsets.all(8.0),
|
|
child: SearchFriends(),
|
|
),
|
|
Expanded(
|
|
child: Consumer<FriendsProvider>(
|
|
builder: (context, friendsProvider, _) {
|
|
final friends = friendsProvider.friendsList;
|
|
|
|
if (friends.isEmpty) {
|
|
return const Center(
|
|
child: Text(
|
|
'Aucun ami trouvé',
|
|
style: TextStyle(color: Colors.white70),
|
|
),
|
|
);
|
|
}
|
|
|
|
return ListView.builder(
|
|
physics: const BouncingScrollPhysics(),
|
|
itemCount: friends.length,
|
|
itemBuilder: (context, index) {
|
|
final friend = friends[index];
|
|
return Dismissible(
|
|
key: Key(friend.friendId),
|
|
background: Container(
|
|
color: Colors.redAccent,
|
|
alignment: Alignment.centerLeft,
|
|
padding: const EdgeInsets.only(left: 20),
|
|
child: const Icon(Icons.delete, color: Colors.white),
|
|
),
|
|
onDismissed: (direction) {
|
|
debugPrint("[LOG] Suppression de l'ami avec l'ID : ${friend.friendId}");
|
|
friendsProvider.removeFriend(friend.friendId);
|
|
},
|
|
child: FriendExpandingCard(
|
|
name: friend.firstName ?? 'Ami inconnu',
|
|
imageUrl: friend.imageUrl ?? '',
|
|
description: "Amis depuis ${friend.friendId}",
|
|
onTap: () => _navigateToFriendDetail(context, friend),
|
|
onMessageTap: () {
|
|
debugPrint("[LOG] Envoi d'un message à l'ami : ${friend.firstName ?? 'Ami inconnu'}");
|
|
},
|
|
onRemoveTap: () {
|
|
debugPrint("[LOG] Tentative de suppression de l'ami : ${friend.firstName ?? 'Ami inconnu'}");
|
|
friendsProvider.removeFriend(friend.friendId);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Navigue vers l'écran des détails de l'utilisateur (ami) récupéré via son `friendId`.
|
|
void _navigateToFriendDetail(BuildContext context, Friend friend) {
|
|
debugPrint("[LOG] Navigation vers les détails de l'ami : ${friend.firstName ?? 'Ami inconnu'}");
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) => FriendDetailScreen(
|
|
name: friend.firstName ?? 'Ami inconnu',
|
|
imageUrl: friend.imageUrl ?? '',
|
|
friendId: friend.friendId, // Passer l'ID pour récupérer les détails complets
|
|
),
|
|
));
|
|
}
|
|
}
|