2024-10-04 11:59:55 +04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:test_app/domain/card.dart';
|
|
|
|
|
|
|
|
part 'card_image.dart';
|
|
|
|
part 'card_like.dart';
|
|
|
|
part 'card_text.dart';
|
2024-10-04 11:07:54 +04:00
|
|
|
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
|
2024-10-04 11:59:55 +04:00
|
|
|
class HomeCard extends StatelessWidget {
|
2024-10-04 11:07:54 +04:00
|
|
|
final String text;
|
|
|
|
final String descriptionText;
|
|
|
|
final IconData icon;
|
|
|
|
final String? imageUrl;
|
|
|
|
final OnLikeCallback onLike;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
|
2024-10-04 11:59:55 +04:00
|
|
|
const HomeCard(
|
2024-10-04 11:07:54 +04:00
|
|
|
this.text, {
|
|
|
|
this.icon = Icons.ac_unit_outlined,
|
|
|
|
required this.descriptionText,
|
|
|
|
this.imageUrl,
|
|
|
|
this.onLike,
|
|
|
|
this.onTap,
|
2024-10-04 11:59:55 +04:00
|
|
|
super.key,
|
2024-10-04 11:07:54 +04:00
|
|
|
});
|
|
|
|
|
2024-10-04 11:59:55 +04:00
|
|
|
factory HomeCard.fromData(
|
2024-10-04 11:07:54 +04:00
|
|
|
CardData data, {
|
|
|
|
OnLikeCallback? onLike,
|
|
|
|
VoidCallback? onTap,
|
|
|
|
}) =>
|
2024-10-04 11:59:55 +04:00
|
|
|
HomeCard(
|
2024-10-04 11:07:54 +04:00
|
|
|
data.text,
|
|
|
|
descriptionText: data.descriptionText,
|
|
|
|
icon: data.icon,
|
|
|
|
imageUrl: data.imageUrl,
|
|
|
|
onLike: onLike,
|
|
|
|
onTap: onTap,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
2024-10-04 11:59:55 +04:00
|
|
|
onTap: onTap,
|
2024-10-04 11:07:54 +04:00
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.only(top: 8, bottom: 8),
|
|
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
|
|
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: [
|
2024-10-04 11:59:55 +04:00
|
|
|
_CardImage(imageUrl ?? ''),
|
|
|
|
_CardText(
|
|
|
|
text,
|
|
|
|
descriptionText: descriptionText,
|
2024-10-04 11:07:54 +04:00
|
|
|
),
|
2024-10-04 11:59:55 +04:00
|
|
|
_CardLike(
|
|
|
|
onLike,
|
|
|
|
text: text,
|
2024-10-04 11:07:54 +04:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|