134 lines
4.1 KiB
Dart
Raw Normal View History

2024-10-14 20:41:05 +04:00
part of 'home_page.dart';
2024-11-25 23:02:19 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked);
2024-10-14 20:41:05 +04:00
2024-11-25 23:02:19 +04:00
class _Card extends StatelessWidget {
2024-10-14 20:41:05 +04:00
final String text;
final String descriptionText;
final String? imageUrl;
final OnLikeCallback? onLike;
final VoidCallback? onTap;
2024-11-25 23:02:19 +04:00
final String id;
final bool isLiked;
2024-10-14 20:41:05 +04:00
2024-11-25 23:02:19 +04:00
const _Card(this.text, {
2024-10-14 20:41:05 +04:00
required this.descriptionText,
this.imageUrl,
this.onLike,
this.onTap,
2024-11-25 23:02:19 +04:00
required this.id,
this.isLiked = false,
2024-10-14 20:41:05 +04:00
});
2024-11-25 23:02:19 +04:00
factory _Card.fromData(CardData data, {
2024-10-14 20:41:05 +04:00
OnLikeCallback? onLike,
VoidCallback? onTap,
2024-11-25 23:02:19 +04:00
bool isLiked = false,
2024-10-14 20:41:05 +04:00
}) =>
_Card(
2024-10-29 01:49:32 +04:00
data.text!,
2024-11-25 23:02:19 +04:00
id: data.id,
2024-10-29 01:49:32 +04:00
descriptionText: data.descriptionText!,
2024-10-14 20:41:05 +04:00
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
2024-11-25 23:02:19 +04:00
isLiked: isLiked,
2024-10-14 20:41:05 +04:00
);
@override
Widget build(BuildContext context) {
return GestureDetector(
2024-11-25 23:02:19 +04:00
onTap: onTap,
2024-10-14 20:41:05 +04:00
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Container(
margin: const EdgeInsets.only(top: 16),
//padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurpleAccent,
borderRadius: BorderRadius.circular(20),
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(20),
topLeft: Radius.circular(20),
),
child: SizedBox(
height: 160,
width: 160,
child: Stack(
children: [
Positioned.fill(
child: Image.network(
2024-11-25 23:02:19 +04:00
imageUrl ?? '',
2024-10-14 20:41:05 +04:00
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2024-11-25 23:02:19 +04:00
text,
style: Theme
.of(context)
.textTheme
.titleLarge,
2024-10-14 20:41:05 +04:00
),
Text(
2024-11-25 23:02:19 +04:00
descriptionText,
style: Theme
.of(context)
.textTheme
.bodyLarge,
2024-10-14 20:41:05 +04:00
)
],
),
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 15,
bottom: 15,
),
child: GestureDetector(
2024-11-25 23:02:19 +04:00
onTap: () => onLike?.call(id, text, isLiked),
2024-10-14 20:41:05 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(
2024-11-25 23:02:19 +04:00
Icons.favorite,
color: Colors.purpleAccent,
key: ValueKey<int>(0),
)
2024-10-14 20:41:05 +04:00
: const Icon(
2024-11-25 23:02:19 +04:00
Icons.favorite_border,
key: ValueKey<int>(1),
),
2024-10-14 20:41:05 +04:00
),
),
),
)
],
),
),
),
),
);
}
}