173 lines
5.1 KiB
Dart
173 lines
5.1 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
class _Card extends StatefulWidget {
|
|
final String text;
|
|
final String descriptionText;
|
|
final IconData icon;
|
|
final String? imageUrl;
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const _Card(
|
|
this.text, {
|
|
this.icon = Icons.catching_pokemon,
|
|
required this.descriptionText,
|
|
this.imageUrl,
|
|
this.onLike,
|
|
this.onTap,
|
|
});
|
|
|
|
factory _Card.fromData(
|
|
CardData data, {
|
|
OnLikeCallback onLike,
|
|
VoidCallback? onTap,
|
|
}) =>
|
|
_Card(
|
|
data.text,
|
|
descriptionText: data.descriptionText,
|
|
icon: data.icon,
|
|
imageUrl: data.imageUrl,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
);
|
|
|
|
@override
|
|
State<_Card> createState() => _CardState();
|
|
}
|
|
|
|
class _CardState extends State<_Card> {
|
|
bool isLiked = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onLongPress: widget.onTap,
|
|
onDoubleTap: () {
|
|
setState(() {
|
|
isLiked = !isLiked;
|
|
});
|
|
widget.onLike?.call(widget.text, isLiked);
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.all(16),
|
|
constraints: const BoxConstraints(minHeight: 170),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey,
|
|
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: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 10,
|
|
top: 10,
|
|
right: 3,
|
|
bottom: 10
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(15),
|
|
child: SizedBox(
|
|
height: double.infinity,
|
|
width: 150,
|
|
child: Image.network(
|
|
widget.imageUrl ?? '',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
Expanded(
|
|
child: Stack(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 8.0,
|
|
right: 8.0,
|
|
bottom: 16.0,
|
|
),
|
|
child: Icon(
|
|
widget.icon,
|
|
),
|
|
),
|
|
),
|
|
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 3.0, top: 3.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
widget.text,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
widget.descriptionText,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
]
|
|
),
|
|
),
|
|
],
|
|
)
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 8.0,
|
|
right: 16.0,
|
|
bottom: 16.0,
|
|
),
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
isLiked = !isLiked;
|
|
});
|
|
widget.onLike?.call(widget.text, isLiked);
|
|
},
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 300),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.thumb_up,
|
|
color: Colors.redAccent,
|
|
key: ValueKey<int>(0),
|
|
)
|
|
: const Icon(
|
|
Icons.thumb_up_off_alt,
|
|
key: ValueKey<int>(1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |