118 lines
3.3 KiB
Dart
Raw Normal View History

part of 'home_page.dart';
2024-11-19 11:41:18 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
2024-11-14 14:28:07 +04:00
class _Card extends StatelessWidget {
final String text;
final String descriptionText;
2024-11-12 00:23:53 +04:00
final String? fullName;
final IconData icon;
final String? imageUrl;
final OnLikeCallback onLike;
final VoidCallback? onTap;
2024-11-19 11:41:18 +04:00
final String? id;
2024-11-14 14:28:07 +04:00
final bool isLiked;
const _Card(
2024-11-14 14:28:07 +04:00
this.text, {
this.icon = Icons.catching_pokemon,
required this.descriptionText,
required this.fullName,
this.imageUrl,
this.onLike,
this.onTap,
this.id,
this.isLiked = false,
});
factory _Card.fromData(
2024-11-14 14:28:07 +04:00
CardData data, {
OnLikeCallback onLike,
VoidCallback? onTap,
bool isLiked = false,
}) =>
_Card(
data.text,
descriptionText: data.descriptionText,
2024-11-04 16:34:24 +04:00
fullName: data.fullName,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
2024-11-14 14:28:07 +04:00
isLiked: isLiked,
2024-11-19 11:41:18 +04:00
id: data.id.toString()
);
@override
Widget build(BuildContext context) {
return GestureDetector(
2024-11-14 14:28:07 +04:00
onTap: onTap,
2024-11-04 16:34:24 +04:00
child: Card(
margin: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: SizedBox(
height: 250,
width: double.infinity,
child: Image.network(
2024-11-14 14:28:07 +04:00
imageUrl ?? '',
2024-11-04 16:34:24 +04:00
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
2024-11-04 16:34:24 +04:00
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2024-11-14 14:28:07 +04:00
fullName ?? 'Default Name',
2024-11-04 16:34:24 +04:00
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
2024-11-14 14:28:07 +04:00
fontSize: 20.0,
fontFamily: 'Times New Roman',
),
),
2024-11-04 16:34:24 +04:00
Text(
2024-11-14 14:28:07 +04:00
descriptionText,
2024-11-04 16:34:24 +04:00
style: Theme.of(context).textTheme.bodyMedium,
),
2024-11-04 16:34:24 +04:00
],
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 16.0,
bottom: 16.0,
),
child: GestureDetector(
2024-11-14 14:28:07 +04:00
onTap: () => onLike?.call(id, text, isLiked),
2024-11-04 16:34:24 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(
Icons.favorite,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
: const Icon(
Icons.favorite_border,
key: ValueKey<int>(1),
),
),
),
),
2024-11-04 16:34:24 +04:00
),
],
),
),
);
}
2024-11-14 14:28:07 +04:00
}