part of 'home_page.dart'; typedef OnLikeCallback = void Function(String title, bool isLiked)?; class _Card extends StatefulWidget { final String title; final String description; final IconData icon; final String? imageUrl; final OnLikeCallback onLike; final VoidCallback? onTap; const _Card({ super.key, required this.title, required this.description, this.icon = Icons.hail, this.imageUrl, this.onLike, this.onTap, }); factory _Card.fromData( CardData data, { final OnLikeCallback onLike, VoidCallback? onTap, }) => _Card( title: data.title, description: data.description, icon: data.icon, imageUrl: data.imageUrl, onLike: onLike, onTap: onTap, ); @override State<_Card> createState() => _CardState(); } class _CardState extends State<_Card> { bool isLiked = false; @override Widget build(BuildContext context) { return GestureDetector( onTap: widget.onTap, child: Container( margin: const EdgeInsets.fromLTRB(20, 8, 20, 8), constraints: const BoxConstraints(minHeight: 140), decoration: BoxDecoration( color: Colors.deepPurple.shade200, borderRadius: BorderRadius.circular(15), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.5), spreadRadius: 4, offset: const Offset(0, 5), blurRadius: 6, ) ], ), child: IntrinsicHeight( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.end, children: [ ClipRRect( borderRadius: const BorderRadius.only( bottomLeft: Radius.circular(15), topLeft: Radius.circular(15), ), child: SizedBox( height: double.infinity, width: 100, child: Image.network( widget.imageUrl ?? '', fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Placeholder(), ), ), ), Flexible( child: Padding( padding: const EdgeInsets.only(left: 12.0, top: 12, bottom: 12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.title, style: Theme.of(context).textTheme.headlineLarge, ), Text( widget.description, style: Theme.of(context).textTheme.bodyLarge), ], ), ), ), Align( alignment: Alignment.bottomRight, child: Padding( padding: const EdgeInsets.fromLTRB(8, 0, 16, 16), child: GestureDetector( onTap: () { setState(() { isLiked = !isLiked; }); widget.onLike?.call(widget.title, isLiked); }, child: AnimatedSwitcher( duration: const Duration(milliseconds: 100), child: isLiked ? const Icon( Icons.favorite, color: Colors.redAccent, key: ValueKey(0), ) : const Icon( Icons.favorite_border, key: ValueKey(1), ), ), ), ), ), ], ), ), ), ); } }