140 lines
3.8 KiB
Dart
140 lines
3.8 KiB
Dart
part of 'home_page.dart';
|
|
|
|
class _CardData {
|
|
final String title;
|
|
final String description;
|
|
final IconData icon;
|
|
final String? imageUrl;
|
|
|
|
_CardData({
|
|
required this.title,
|
|
required this.description,
|
|
this.icon = Icons.adb,
|
|
this.imageUrl,
|
|
});
|
|
}
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
class _Card extends StatefulWidget {
|
|
final String title;
|
|
final String description;
|
|
final IconData icon;
|
|
final String? imageUrl;
|
|
final OnLikeCallback onLike;
|
|
|
|
const _Card({
|
|
super.key,
|
|
required this.title,
|
|
required this.description,
|
|
this.icon = Icons.hail,
|
|
this.imageUrl,
|
|
this.onLike,
|
|
});
|
|
|
|
factory _Card.fromData(
|
|
_CardData data, {
|
|
final OnLikeCallback onLike,
|
|
}) => _Card(
|
|
title: data.title,
|
|
description: data.description,
|
|
icon: data.icon,
|
|
imageUrl: data.imageUrl,
|
|
onLike: onLike,
|
|
);
|
|
|
|
@override
|
|
State<_Card> createState() => _CardState();
|
|
}
|
|
|
|
class _CardState extends State<_Card> {
|
|
bool isLiked = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.fromLTRB(20, 8, 20, 8),
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
decoration: BoxDecoration(
|
|
color: Colors.deepPurple.shade200,
|
|
borderRadius: BorderRadius.circular(15),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.5),
|
|
spreadRadius: 4,
|
|
offset: const Offset(0, 5),
|
|
blurRadius: 6,
|
|
)
|
|
],
|
|
),
|
|
child: IntrinsicHeight(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(15),
|
|
topLeft: Radius.circular(15),
|
|
),
|
|
child: SizedBox(
|
|
height: double.infinity,
|
|
width: 100,
|
|
child: Image.network(
|
|
widget.imageUrl ?? '',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
),
|
|
Flexible(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 12.0, top: 12, bottom: 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
widget.title,
|
|
style: Theme.of(context).textTheme.headlineLarge,
|
|
),
|
|
Text(
|
|
widget.description,
|
|
style: Theme.of(context).textTheme.bodyLarge),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 16, 16),
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
isLiked = !isLiked;
|
|
});
|
|
widget.onLike?.call(widget.title, isLiked);
|
|
},
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 100),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.favorite,
|
|
color: Colors.redAccent,
|
|
key: ValueKey(0),
|
|
)
|
|
: const Icon(
|
|
Icons.favorite_border,
|
|
key: ValueKey(1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|