fix(chat): Correction race condition + Implémentation TODOs
## 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
This commit is contained in:
@@ -1,62 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FriendSuggestions extends StatelessWidget {
|
||||
final Size size;
|
||||
import '../../data/providers/friends_provider.dart';
|
||||
import '../../data/models/friend_suggestion_model.dart';
|
||||
import 'friend_suggestion_card.dart';
|
||||
|
||||
const FriendSuggestions({required this.size, Key? key}) : super(key: key);
|
||||
/// 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 Column(
|
||||
children: List.generate(3, (index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 20),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
width: size.width,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[850],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 3),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundImage: AssetImage('lib/assets/images/friend_placeholder.png'),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Nom d\'utilisateur',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
print('Ajouter comme ami');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.teal,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('Ajouter'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 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(),
|
||||
);
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user