120 lines
3.8 KiB
Dart
Raw Normal View History

2024-10-25 21:48:27 +04:00
part of 'home_page.dart';
2024-12-17 17:07:44 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
2024-10-25 21:48:27 +04:00
2024-12-17 17:07:44 +04:00
class _Card extends StatelessWidget {
2024-10-25 21:48:27 +04:00
final String text;
final String description;
final String? imgUrl;
2024-12-17 17:07:44 +04:00
final OnLikeCallback onLike;
2024-10-25 21:48:27 +04:00
final VoidCallback? onTap;
2024-12-17 17:07:44 +04:00
final String? id;
final bool isLiked;
2024-10-25 21:48:27 +04:00
const _Card(
2024-12-17 17:07:44 +04:00
this.text, {
required this.description,
this.imgUrl,
this.onLike,
this.onTap,
this.id,
this.isLiked = false,
});
2024-10-25 21:48:27 +04:00
2024-12-17 17:07:44 +04:00
factory _Card.fromData(
CardData data, {
OnLikeCallback onLike,
VoidCallback? onTap,
bool isLiked = false,
}) =>
_Card(
2024-12-17 17:19:10 +04:00
data.name,
2024-12-17 14:33:28 +04:00
description: data.description,
2024-12-17 17:19:10 +04:00
imgUrl: data.img,
2024-12-17 14:33:28 +04:00
onLike: onLike,
onTap: onTap,
2024-12-17 17:07:44 +04:00
isLiked: isLiked,
id: data.id,
2024-12-17 14:33:28 +04:00
);
2024-10-25 21:48:27 +04:00
@override
Widget build(BuildContext context) {
2024-12-17 17:07:44 +04:00
return GestureDetector(
onTap: onTap,
child: Container(
margin: const EdgeInsets.only(bottom: 20),
decoration:
2024-12-20 18:13:20 +04:00
BoxDecoration(color: Color(0xFF272727), borderRadius: BorderRadius.circular(20),
border: Border.all( // Задаем рамку
color: Colors.white12, // Цвет рамки
width: 2, // Толщина рамки
),
),
2024-12-17 17:07:44 +04:00
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Stack(children: [
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
child: Image.network(
imgUrl ?? '',
errorBuilder: (_, __, ___) => const Placeholder(),
height: 370,
alignment: Alignment.topCenter,
fit: BoxFit.cover,
width: double.infinity,
),
),
]),
Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
text,
style: const TextStyle(
2024-12-20 18:13:20 +04:00
color: Colors.white70,
2024-12-17 17:07:44 +04:00
fontSize: 30,
fontWeight: FontWeight.bold,
),
2024-10-25 21:48:27 +04:00
),
2024-12-17 14:33:28 +04:00
),
2024-12-17 17:07:44 +04:00
Text(
description,
style: const TextStyle(
2024-12-20 18:13:20 +04:00
color: Colors.white70,
2024-12-17 17:07:44 +04:00
fontSize: 20,
fontWeight: FontWeight.normal,
),
2024-12-17 14:33:28 +04:00
),
2024-12-17 17:07:44 +04:00
Padding(
padding: const EdgeInsets.only(top: 10),
child: GestureDetector(
onTap: () => onLike?.call(id, text, isLiked),
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,
2024-12-20 18:13:20 +04:00
color: Colors.white,
2024-12-17 17:07:44 +04:00
key: ValueKey<int>(1),
),
),
)
)
],
),
2024-12-17 14:33:28 +04:00
),
2024-12-17 17:07:44 +04:00
]),
),
);
}
2024-12-17 14:33:28 +04:00
}