159 lines
4.7 KiB
Dart
Raw Normal View History

2024-11-20 13:52:33 +04:00
part of 'home_page.dart';
2024-12-09 15:14:31 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
2024-11-20 13:52:33 +04:00
2024-12-09 15:14:31 +04:00
class _Card extends StatelessWidget {
2024-11-20 13:52:33 +04:00
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
final OnLikeCallback onLike;
final VoidCallback? onTap;
2024-12-09 15:14:31 +04:00
final String? id;
final bool isLiked;
2024-11-20 13:52:33 +04:00
const _Card(
2024-12-09 15:14:31 +04:00
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl,
this.onLike,
this.onTap,
this.id,
this.isLiked = false,
});
2024-11-20 13:52:33 +04:00
factory _Card.fromData(
2024-12-09 15:14:31 +04:00
CardData data, {
2024-11-20 13:52:33 +04:00
OnLikeCallback onLike,
VoidCallback? onTap,
2024-12-09 15:14:31 +04:00
bool isLiked = false,
2024-11-20 13:52:33 +04:00
}) =>
_Card(
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
2024-12-09 15:14:31 +04:00
isLiked: isLiked,
id: data.id,
2024-11-20 13:52:33 +04:00
);
2024-12-09 15:14:31 +04:00
/*@override
2024-11-20 13:52:33 +04:00
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
2024-12-09 15:14:31 +04:00
bool isLiked = false;*/
2024-11-20 13:52:33 +04:00
@override
Widget build(BuildContext context) {
return GestureDetector(
2024-12-09 15:14:31 +04:00
onTap: onTap,
onDoubleTap: () => onLike?.call(id, text, isLiked),
2024-11-20 13:52:33 +04:00
child: Container(
margin: const EdgeInsets.all(16),
constraints: const BoxConstraints(minHeight: 170),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-12-09 15:14:31 +04:00
Padding(
padding: const EdgeInsets.only(left: 10, top: 10, right: 3, bottom: 10),
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: SizedBox(
height: double.infinity,
width: 150,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
2024-11-20 13:52:33 +04:00
),
2024-12-09 15:14:31 +04:00
),
2024-11-20 13:52:33 +04:00
),
),
Expanded(
2024-12-09 15:14:31 +04:00
child: Stack(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
bottom: 16.0,
),
child: Icon(
icon,
2024-11-20 13:52:33 +04:00
),
),
2024-12-09 15:14:31 +04:00
),
Padding(
padding: const EdgeInsets.only(left: 3.0, top: 3.0),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
2024-11-20 13:52:33 +04:00
Text(
2024-12-09 15:14:31 +04:00
text,
2024-11-20 13:52:33 +04:00
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
Text(
2024-12-09 15:14:31 +04:00
descriptionText,
2024-11-20 13:52:33 +04:00
style: const TextStyle(
color: Colors.white,
fontSize: 13,
2024-12-09 15:14:31 +04:00
),
2024-11-20 13:52:33 +04:00
),
2024-12-09 15:14:31 +04:00
]),
),
],
)),
2024-11-20 13:52:33 +04:00
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
right: 16.0,
bottom: 16.0,
),
child: GestureDetector(
2024-12-09 15:14:31 +04:00
onTap: () => onLike?.call(id, text, isLiked),
2024-11-20 13:52:33 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(
2024-12-09 15:14:31 +04:00
Icons.thumb_up,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
2024-11-20 13:52:33 +04:00
: const Icon(
2024-12-09 15:14:31 +04:00
Icons.thumb_up_off_alt,
key: ValueKey<int>(1),
),
2024-11-20 13:52:33 +04:00
),
),
),
),
],
),
),
),
);
}
2024-12-09 15:14:31 +04:00
}