## Corrections Critiques ### Race Condition - Statuts de Messages - Fix : Les icônes de statut (✓, ✓✓, ✓✓ bleu) ne s'affichaient pas - Cause : WebSocket delivery confirmations arrivaient avant messages locaux - Solution : Pattern Optimistic UI dans chat_bloc.dart - Création message temporaire immédiate - Ajout à la liste AVANT requête HTTP - Remplacement par message serveur à la réponse - Fichier : lib/presentation/state_management/chat_bloc.dart ## Implémentation TODOs (13/21) ### Social (social_header_widget.dart) - ✅ Copier lien du post dans presse-papiers - ✅ Partage natif via Share.share() - ✅ Dialogue de signalement avec 5 raisons ### Partage (share_post_dialog.dart) - ✅ Interface sélection d'amis avec checkboxes - ✅ Partage externe via Share API ### Média (media_upload_service.dart) - ✅ Parsing JSON réponse backend - ✅ Méthode deleteMedia() pour suppression - ✅ Génération miniature vidéo ### Posts (create_post_dialog.dart, edit_post_dialog.dart) - ✅ Extraction URL depuis uploads - ✅ Documentation chargement médias ### Chat (conversations_screen.dart) - ✅ Navigation vers notifications - ✅ ConversationSearchDelegate pour recherche ## Nouveaux Fichiers ### Configuration - build-prod.ps1 : Script build production avec dart-define - lib/core/constants/env_config.dart : Gestion environnements ### Documentation - TODOS_IMPLEMENTED.md : Documentation complète TODOs ## Améliorations ### Architecture - Refactoring injection de dépendances - Amélioration routing et navigation - Optimisation providers (UserProvider, FriendsProvider) ### UI/UX - Amélioration thème et couleurs - Optimisation animations - Meilleure gestion erreurs ### Services - Configuration API avec env_config - Amélioration datasources (events, users) - Optimisation modèles de données
128 lines
3.7 KiB
Dart
128 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../data/providers/friends_provider.dart';
|
|
import '../../data/models/friend_suggestion_model.dart';
|
|
import 'friend_suggestion_card.dart';
|
|
|
|
/// Widget pour afficher une liste de suggestions d'amis.
|
|
///
|
|
/// Ce widget charge et affiche automatiquement les suggestions d'amis
|
|
/// basées sur les amis en commun et d'autres critères.
|
|
///
|
|
/// **Principe WOU (Write Once Use) :** Ce widget encapsule toute la
|
|
/// logique de chargement et d'affichage, utilisable partout.
|
|
class FriendSuggestions extends StatefulWidget {
|
|
const FriendSuggestions({
|
|
this.maxSuggestions = 5,
|
|
super.key,
|
|
});
|
|
|
|
/// Nombre maximum de suggestions à afficher
|
|
final int maxSuggestions;
|
|
|
|
@override
|
|
State<FriendSuggestions> createState() => _FriendSuggestionsState();
|
|
}
|
|
|
|
class _FriendSuggestionsState extends State<FriendSuggestions> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Charger les suggestions au démarrage
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_loadSuggestions();
|
|
});
|
|
}
|
|
|
|
Future<void> _loadSuggestions() async {
|
|
final provider = Provider.of<FriendsProvider>(context, listen: false);
|
|
try {
|
|
await provider.fetchFriendSuggestions(limit: widget.maxSuggestions);
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Impossible de charger les suggestions: $e'),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _addFriend(BuildContext context, String friendId) async {
|
|
final provider = Provider.of<FriendsProvider>(context, listen: false);
|
|
|
|
try {
|
|
await provider.addFriend(friendId);
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Demande d\'ami envoyée avec succès'),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
|
|
// Recharger les suggestions pour mettre à jour la liste
|
|
await _loadSuggestions();
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Erreur: ${e.toString()}'),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<FriendsProvider>(
|
|
builder: (context, provider, child) {
|
|
// Afficher un loader pendant le chargement
|
|
if (provider.isLoadingSuggestions) {
|
|
return const Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(20),
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Afficher un message si aucune suggestion
|
|
if (provider.friendSuggestions.isEmpty) {
|
|
return const Padding(
|
|
padding: EdgeInsets.all(20),
|
|
child: Center(
|
|
child: Text(
|
|
'Aucune suggestion disponible pour le moment',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Afficher la liste des suggestions
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: provider.friendSuggestions.map((suggestion) {
|
|
final suggestionModel = FriendSuggestionModel.fromJson(suggestion);
|
|
return FriendSuggestionCard(
|
|
suggestion: suggestion,
|
|
onAddFriend: () => _addFriend(context, suggestionModel.userId),
|
|
);
|
|
}).toList(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|