PMU_2024/lib/presentation/home_page/card.dart

136 lines
4.4 KiB
Dart
Raw Permalink Normal View History

2024-09-23 20:37:45 +04:00
part of 'home_page.dart';
typedef OnLikeCallBack = void Function(String? id, String title, bool isLiked)?;
2024-09-23 20:37:45 +04:00
class _Card extends StatelessWidget {
2024-09-23 20:37:45 +04:00
final String text;
final IconData icon;
final String descText;
final String? imageUrl;
final OnLikeCallBack onLike;
final VoidCallback? onTap;
final String? id;
final bool isLiked;
2024-09-23 20:37:45 +04:00
const _Card(
this.text, {
this.icon = Icons.ac_unit_sharp,
required this.descText,
this.imageUrl,
this.onLike,
this.onTap,
this.id,
this.isLiked = false,
});
2024-09-23 20:37:45 +04:00
factory _Card.fromData(
CardData data, {
OnLikeCallBack onLike,
VoidCallback? onTap,
bool isLiked = false,
2024-09-23 20:37:45 +04:00
}) =>
_Card(
data.text,
descText: data.descText,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
isLiked: isLiked,
id: data.id,
2024-09-23 20:37:45 +04:00
);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: GestureDetector(
onTap: onTap,
2024-09-23 20:37:45 +04:00
child: SizedBox(
height: 150,
child: Container(
margin: const EdgeInsets.only(top: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
border: Border.all(
color: Colors.lightBlue,
width: 3,
)),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(10),
topLeft: Radius.circular(10),
),
child: SizedBox(
height: double.infinity,
width: 120,
child: Image.network(
imageUrl ?? '',
2024-09-23 20:37:45 +04:00
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 8.0, top: 4.0, right: 4.0, bottom: 4.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
2024-09-23 20:37:45 +04:00
maxLines: 1,
overflow: TextOverflow.ellipsis,
2024-09-23 22:21:08 +04:00
style: const TextStyle(
2024-09-23 20:37:45 +04:00
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: 26),
),
Text(
descText,
2024-09-23 20:37:45 +04:00
maxLines: 5,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall,
)
],
),
),
),
//const Spacer(),
Align(
child: Padding(
padding: const EdgeInsets.only(
left: 8.0, top: 4.0, right: 8.0, bottom: 4.0),
child: GestureDetector(
onTap: () => onLike?.call(id, text, isLiked),
2024-09-23 20:37:45 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(
Icons.favorite,
color: Colors.red,
key: ValueKey<int>(0),
)
: const Icon(
Icons.favorite_border,
key: ValueKey<int>(1),
)),
),
),
)
],
),
),
),
),
),
);
}
}