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