120 lines
3.8 KiB
Dart
120 lines
3.8 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|
|
|
class _Card extends StatelessWidget {
|
|
final String text;
|
|
final String description;
|
|
final String? imgUrl;
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
final String? id;
|
|
final bool isLiked;
|
|
|
|
const _Card(
|
|
this.text, {
|
|
required this.description,
|
|
this.imgUrl,
|
|
this.onLike,
|
|
this.onTap,
|
|
this.id,
|
|
this.isLiked = false,
|
|
});
|
|
|
|
factory _Card.fromData(
|
|
CardData data, {
|
|
OnLikeCallback onLike,
|
|
VoidCallback? onTap,
|
|
bool isLiked = false,
|
|
}) =>
|
|
_Card(
|
|
data.name,
|
|
description: data.description,
|
|
imgUrl: data.img,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
isLiked: isLiked,
|
|
id: data.id,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
margin: const EdgeInsets.only(bottom: 20),
|
|
decoration:
|
|
BoxDecoration(color: Color(0xFF272727), borderRadius: BorderRadius.circular(20),
|
|
border: Border.all( // Задаем рамку
|
|
color: Colors.white12, // Цвет рамки
|
|
width: 2, // Толщина рамки
|
|
),
|
|
),
|
|
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(
|
|
color: Colors.white70,
|
|
fontSize: 30,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
description,
|
|
style: const TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.normal,
|
|
),
|
|
),
|
|
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,
|
|
color: Colors.white,
|
|
key: ValueKey<int>(1),
|
|
),
|
|
),
|
|
)
|
|
)
|
|
],
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|