part of 'home_page.dart'; typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?; class _Card extends StatelessWidget { final AppLocale locale; final String title; final String description; final IconData icon; final String? imageUrl; final OnLikeCallback onLike; final VoidCallback? onTap; final String? id; final bool isLiked; const _Card({ super.key, required this.locale, required this.title, required this.description, this.icon = Icons.hail, this.imageUrl, this.onLike, this.onTap, this.id, this.isLiked = false, }); factory _Card.fromData( AppLocale locale, CardData data, { OnLikeCallback onLike, VoidCallback? onTap, bool isLiked = false, }) => _Card( locale: locale, title: data.title, description: data.description, icon: data.icon, imageUrl: data.imageUrl, onLike: onLike, onTap: onTap, isLiked: isLiked, id: data.id, ); @override Widget build(BuildContext context) { return GestureDetector( onTap: 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( 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( title, style: Theme.of(context).textTheme.headlineLarge, ), Text( description, style: Theme.of(context).textTheme.bodyLarge), ], ), ), ), Align( alignment: Alignment.bottomRight, child: Padding( padding: const EdgeInsets.fromLTRB(8, 0, 16, 16), child: GestureDetector( onTap: () => onLike?.call(id, 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), ), ), ), ), ), ], ), ), ), ); } }