refactoring

This commit is contained in:
DahoudG
2024-11-02 15:27:26 +00:00
parent 8e625c1080
commit 9cf96b7acf
44 changed files with 2281 additions and 354 deletions

View File

@@ -0,0 +1,141 @@
import 'package:flutter/material.dart';
/// [FriendExpandingCard] est un widget animé qui s'agrandit pour afficher des options supplémentaires.
/// Il permet de voir plus de détails, d'envoyer un message ou de supprimer un ami.
class FriendExpandingCard extends StatefulWidget {
final String name;
final String imageUrl;
final String description;
final VoidCallback onTap;
final VoidCallback onMessageTap;
final VoidCallback onRemoveTap;
const FriendExpandingCard({
Key? key,
required this.name,
required this.imageUrl,
required this.description,
required this.onTap,
required this.onMessageTap,
required this.onRemoveTap,
}) : super(key: key);
@override
_FriendExpandingCardState createState() => _FriendExpandingCardState();
}
class _FriendExpandingCardState extends State<FriendExpandingCard> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
onLongPress: () {
setState(() {
_isExpanded = !_isExpanded;
});
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
height: _isExpanded ? 200 : 100,
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 5),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey.shade900,
borderRadius: BorderRadius.circular(16),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(2, 2),
),
],
),
child: Column(
children: [
Row(
children: [
Hero(
tag: widget.name,
child: CircleAvatar(
backgroundImage: NetworkImage(widget.imageUrl),
radius: 30,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.name,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5),
AnimatedOpacity(
opacity: _isExpanded ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: Text(
widget.description,
style: const TextStyle(
color: Colors.white70,
fontSize: 14,
),
),
),
],
),
),
if (_isExpanded)
IconButton(
icon: const Icon(Icons.close, color: Colors.white54),
onPressed: () {
setState(() {
_isExpanded = false;
});
},
),
],
),
if (_isExpanded) ...[
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton.icon(
onPressed: widget.onMessageTap,
icon: const Icon(Icons.message, color: Colors.white),
label: const Text('Message'),
style: ElevatedButton.styleFrom(
iconColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
ElevatedButton.icon(
onPressed: widget.onRemoveTap,
icon: const Icon(Icons.delete, color: Colors.red),
label: const Text('Remove'),
style: ElevatedButton.styleFrom(
iconColor: Colors.redAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
],
)
]
],
),
),
);
}
}