140 lines
4.1 KiB
Dart
Raw Normal View History

2024-12-11 12:35:10 +04:00
part of 'home_page.dart';
2024-12-17 12:25:35 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked);
2024-12-11 12:35:10 +04:00
2024-12-17 12:25:35 +04:00
class _Card extends StatelessWidget {
2024-12-11 12:35:10 +04:00
final String text;
2024-12-12 12:06:01 +04:00
final String categoryText;
2024-12-11 13:51:53 +04:00
//final IconData icon;
2024-12-11 12:35:10 +04:00
final String? imageUrl;
final OnLikeCallback? onLike;
final VoidCallback? onTap;
2024-12-17 12:25:35 +04:00
final String uuid;
final bool isLiked;
2024-12-11 12:35:10 +04:00
const _Card(
2024-12-17 12:25:35 +04:00
this.text, {
//this.icon = Icons.abc,
required this.categoryText,
this.imageUrl,
this.onLike,
this.onTap,
required this.uuid,
this.isLiked = false,
});
2024-12-11 12:35:10 +04:00
factory _Card.fromData(
2024-12-17 12:25:35 +04:00
CardData data, {
OnLikeCallback? onLike,
VoidCallback? onTap,
bool isLiked = false,
}) =>
2024-12-11 12:35:10 +04:00
_Card(
2024-12-17 12:25:35 +04:00
uuid: data.uuid,
2024-12-11 13:51:53 +04:00
data.text!,
2024-12-12 12:06:01 +04:00
categoryText: data.categoryText!,
2024-12-11 13:51:53 +04:00
//icon: data.icon,
2024-12-11 12:35:10 +04:00
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
2024-12-17 12:25:35 +04:00
isLiked: isLiked,
2024-12-11 12:35:10 +04:00
);
@override
Widget build(BuildContext context) {
return GestureDetector(
2024-12-17 12:25:35 +04:00
onTap: onTap,
2024-12-11 12:35:10 +04:00
child: Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.grey.shade200),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: SizedBox(
height: 310,
width: double.infinity,
child: Stack(
children: [
Positioned.fill(
child: Image.network(
2024-12-17 12:25:35 +04:00
imageUrl ?? '',
2024-12-12 12:06:01 +04:00
fit: BoxFit.contain,
2024-12-11 12:35:10 +04:00
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
Align(
alignment: Alignment.bottomLeft,
child: Container(
decoration: const BoxDecoration(
color: Colors.purpleAccent,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(20),
),
),
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
child: Text(
'New!!!!',
2024-12-17 12:25:35 +04:00
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(color: Colors.black),
2024-12-11 12:35:10 +04:00
),
),
)
],
),
),
),
const SizedBox(height: 5),
Text(
2024-12-17 12:25:35 +04:00
text,
2024-12-11 12:35:10 +04:00
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
2024-12-17 12:25:35 +04:00
categoryText,
2024-12-11 12:35:10 +04:00
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
2024-12-17 12:25:35 +04:00
fontSize: 20,
),
2024-12-11 12:35:10 +04:00
),
const SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
2024-12-17 12:25:35 +04:00
onTap: () => onLike?.call(uuid, text, isLiked),
2024-12-11 12:35:10 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(
2024-12-17 12:25:35 +04:00
Icons.favorite,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
2024-12-11 12:35:10 +04:00
: const Icon(
2024-12-17 12:25:35 +04:00
Icons.favorite_border,
key: ValueKey<int>(1),
),
2024-12-11 12:35:10 +04:00
),
),
],
),
],
),
),
);
}
}