import 'package:flutter/material.dart'; import '../../data/models/friend_suggestion_model.dart'; /// Widget réutilisable pour afficher une suggestion d'ami. /// /// Ce widget affiche les informations d'un utilisateur suggéré avec /// un bouton pour envoyer une demande d'ami. /// /// **Principe DRY :** Ce widget est réutilisable dans n'importe quelle /// partie de l'application nécessitant d'afficher des suggestions. class FriendSuggestionCard extends StatelessWidget { const FriendSuggestionCard({ required this.suggestion, required this.onAddFriend, super.key, }); /// La suggestion d'ami à afficher final Map suggestion; /// Callback appelé quand l'utilisateur veut ajouter cet ami final VoidCallback onAddFriend; @override Widget build(BuildContext context) { final theme = Theme.of(context); // Parse la suggestion depuis le JSON final suggestionModel = FriendSuggestionModel.fromJson(suggestion); // Obtenir l'initiale pour l'avatar final initial = suggestionModel.fullName.isNotEmpty ? suggestionModel.fullName[0].toUpperCase() : '?'; return Card( margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 6), elevation: 2, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), child: Padding( padding: const EdgeInsets.all(12), child: Row( children: [ // Avatar avec image de profil ou initiale CircleAvatar( radius: 24, backgroundColor: theme.colorScheme.primaryContainer, backgroundImage: suggestionModel.profileImageUrl.isNotEmpty && suggestionModel.profileImageUrl.startsWith('http') ? NetworkImage(suggestionModel.profileImageUrl) : null, child: suggestionModel.profileImageUrl.isEmpty || !suggestionModel.profileImageUrl.startsWith('http') ? Text( initial, style: TextStyle( color: theme.colorScheme.onPrimaryContainer, fontSize: 18, fontWeight: FontWeight.bold, ), ) : null, ), const SizedBox(width: 12), // Informations de la suggestion Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ // Nom complet Text( suggestionModel.fullName, style: theme.textTheme.titleMedium?.copyWith( fontWeight: FontWeight.w600, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), const SizedBox(height: 2), // Raison de la suggestion Text( suggestionModel.suggestionReason, style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurface.withOpacity(0.6), fontSize: 12, ), ), ], ), ), // Bouton d'ajout _buildAddButton(theme), ], ), ), ); } /// Construit le bouton pour ajouter l'ami suggéré Widget _buildAddButton(ThemeData theme) { return Material( color: Colors.transparent, child: InkWell( onTap: onAddFriend, borderRadius: BorderRadius.circular(20), child: Container( padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: theme.colorScheme.primary.withOpacity(0.1), borderRadius: BorderRadius.circular(20), ), child: Icon( Icons.person_add_rounded, color: theme.colorScheme.primary, size: 20, ), ), ), ); } }