131 lines
3.5 KiB
Dart
131 lines
3.5 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,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
class _Card extends StatefulWidget {
|
||
|
final String title;
|
||
|
final String description;
|
||
|
final IconData icon;
|
||
|
final String? imageUrl;
|
||
|
|
||
|
const _Card({
|
||
|
super.key,
|
||
|
required this.title,
|
||
|
required this.description,
|
||
|
this.icon = Icons.hail,
|
||
|
this.imageUrl,
|
||
|
});
|
||
|
|
||
|
factory _Card.fromData(_CardData data) => _Card(
|
||
|
title: data.title,
|
||
|
description: data.description,
|
||
|
icon: data.icon,
|
||
|
imageUrl: data.imageUrl,
|
||
|
);
|
||
|
|
||
|
@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: 15.0),
|
||
|
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;
|
||
|
});
|
||
|
},
|
||
|
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),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|