Bon checkpoint + Refactoring
This commit is contained in:
@@ -45,11 +45,13 @@ class _FriendsScreenState extends State<FriendsScreen> {
|
||||
/// Vérifie si l'utilisateur a atteint le bas de la liste pour charger plus d'amis.
|
||||
void _onScroll() {
|
||||
final provider = Provider.of<FriendsProvider>(context, listen: false);
|
||||
if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent &&
|
||||
|
||||
// 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");
|
||||
// Charger plus d'amis si on atteint la fin de la liste
|
||||
provider.fetchFriends(widget.userId);
|
||||
debugPrint("[LOG] Scroll : Fin de liste atteinte, chargement de la page suivante.");
|
||||
provider.fetchFriends(widget.userId, loadMore: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,10 +67,12 @@ class _FriendsScreenState extends State<FriendsScreen> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () {
|
||||
// Log de l'action de rafraîchissement
|
||||
debugPrint("[LOG] Bouton Refresh : demande de rafraîchissement de la liste des amis");
|
||||
// Rafraîchir la liste des amis
|
||||
friendsProvider.fetchFriends(widget.userId);
|
||||
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.");
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -110,27 +114,29 @@ class _FriendsScreenState extends State<FriendsScreen> {
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
),
|
||||
itemCount: friendsProvider.friendsList.length,
|
||||
itemCount: friendsProvider.friendsList.length + (friendsProvider.isLoading && friendsProvider.hasMore ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
if (index >= friendsProvider.friendsList.length) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final friend = friendsProvider.friendsList[index];
|
||||
debugPrint("[LOG] Affichage de l'ami à l'index $index avec ID : ${friend.friendId}");
|
||||
|
||||
return FriendsCircle(
|
||||
friend: friend,
|
||||
onTap: () {
|
||||
// Log pour l'action de visualisation des détails d'un ami
|
||||
debugPrint("[LOG] Détail : Affichage des détails de l'ami ID : ${friend.friendId}");
|
||||
// Naviguer vers l'écran des détails de l'ami
|
||||
FriendDetailScreen.open(
|
||||
context,
|
||||
friend.friendId,
|
||||
friend.firstName ?? 'Ami inconnu',
|
||||
friend.friendFirstName,
|
||||
friend.imageUrl ?? '',
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user