2024-10-04 14:11:06 +04:00
|
|
|
part of 'home_page.dart';
|
|
|
|
|
2024-10-17 10:44:09 +04:00
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|
|
|
|
|
|
|
class _Card extends StatelessWidget {
|
|
|
|
final String text;
|
|
|
|
final String descriptionText;
|
|
|
|
final String? imageUrl;
|
|
|
|
final OnLikeCallback onLike;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
final String? id;
|
|
|
|
final bool isLiked;
|
|
|
|
|
|
|
|
const _Card(
|
|
|
|
this.text, {
|
|
|
|
required this.descriptionText,
|
|
|
|
this.imageUrl,
|
|
|
|
this.onLike,
|
|
|
|
this.onTap,
|
|
|
|
this.id,
|
|
|
|
this.isLiked = false,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory _Card.fromData(
|
|
|
|
CardData data, {
|
|
|
|
OnLikeCallback onLike,
|
|
|
|
VoidCallback? onTap,
|
|
|
|
bool isLiked = false,
|
|
|
|
}) =>
|
|
|
|
_Card(
|
|
|
|
data.text,
|
|
|
|
descriptionText: data.descriptionText,
|
|
|
|
imageUrl: data.imageUrl,
|
|
|
|
onLike: onLike,
|
|
|
|
onTap: onTap,
|
|
|
|
isLiked: isLiked,
|
|
|
|
id: data.id,
|
|
|
|
);
|
2024-10-04 14:11:06 +04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
2024-10-17 10:44:09 +04:00
|
|
|
onTap: onTap,
|
2024-10-04 14:11:06 +04:00
|
|
|
child: Container(
|
2024-10-17 10:44:09 +04:00
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
constraints: const BoxConstraints(minHeight: 160),
|
2024-10-04 14:11:06 +04:00
|
|
|
decoration: BoxDecoration(
|
2024-10-17 10:44:09 +04:00
|
|
|
color: Colors.white70,
|
2024-10-04 14:11:06 +04:00
|
|
|
borderRadius: BorderRadius.circular(20),
|
2024-10-17 10:44:09 +04:00
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.grey.withOpacity(.5),
|
|
|
|
spreadRadius: 4,
|
|
|
|
offset: const Offset(0, 5),
|
|
|
|
blurRadius: 8,
|
|
|
|
),
|
|
|
|
],
|
2024-10-04 14:11:06 +04:00
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
2024-10-17 10:44:09 +04:00
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomLeft: Radius.circular(20),
|
|
|
|
topLeft: Radius.circular(20),
|
|
|
|
),
|
2024-10-04 14:11:06 +04:00
|
|
|
child: SizedBox(
|
2024-10-17 10:44:09 +04:00
|
|
|
height: double.infinity,
|
|
|
|
width: 120,
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Positioned.fill(
|
|
|
|
child: Image.network(
|
|
|
|
imageUrl ?? '',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-10-04 14:11:06 +04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-10-17 10:44:09 +04:00
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
descriptionText,
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-10-04 14:11:06 +04:00
|
|
|
),
|
2024-10-17 10:44:09 +04:00
|
|
|
),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8, right: 16, bottom: 16),
|
2024-10-04 14:11:06 +04:00
|
|
|
child: GestureDetector(
|
2024-10-17 10:44:09 +04:00
|
|
|
onTap: () => onLike?.call(id, text, isLiked),
|
2024-10-04 14:11:06 +04:00
|
|
|
child: AnimatedSwitcher(
|
2024-10-17 10:44:09 +04:00
|
|
|
duration: const Duration(milliseconds: 200),
|
2024-10-04 14:11:06 +04:00
|
|
|
child: isLiked
|
|
|
|
? const Icon(
|
2024-10-17 10:44:09 +04:00
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.redAccent,
|
|
|
|
key: ValueKey<int>(0),
|
|
|
|
)
|
|
|
|
: const Icon(
|
|
|
|
Icons.favorite_border,
|
|
|
|
key: ValueKey<int>(1),
|
|
|
|
),
|
2024-10-04 14:11:06 +04:00
|
|
|
),
|
2024-10-17 10:44:09 +04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-10-04 14:11:06 +04:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-10-17 10:44:09 +04:00
|
|
|
}
|