2024-11-27 23:10:56 +04:00

118 lines
3.8 KiB
Dart

part of 'home_page.dart';
typedef OnLikeCallBack = void Function(String title, bool isLiked)?;
class _Card extends StatefulWidget {
final String text;
final String description;
final String? imgUrl;
final OnLikeCallBack onLike;
final VoidCallback? onTap;
const _Card(
this.text, {
required this.description,
this.imgUrl,
this.onLike,
this.onTap,
});
factory _Card.fromData(CardData data, {OnLikeCallBack onLike, VoidCallback? onTap}) => _Card(
data.text,
description: data.description,
imgUrl: data.imgUrl,
onLike: onLike,
onTap: onTap,
);
@override
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
child: Container(
margin: const EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 1,
offset: const Offset(0, 0),
blurRadius: 15,
)
]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
children: [
ClipRRect(
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
child: Image.network(
widget.imgUrl ?? '',
errorBuilder: (_, __, ___) => const Placeholder(),
height: 370,
alignment: Alignment.topCenter,
fit: BoxFit.cover,
width: double.infinity,
),
),
]
),
Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom:10),
child: Text(
widget.text,
style: const TextStyle(
color: Color(0xff4c4c4c),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
),
Text(
widget.description,
style: const TextStyle(
color: Color(0xff9c9c9c),
fontSize: 20,
fontWeight: FontWeight.normal,
),
),
Padding(
padding: const EdgeInsets.only(top:10),
child: GestureDetector(
onTap:(){
setState(() {
isLiked = !isLiked;
});
widget.onLike?.call(widget.text, isLiked);
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: isLiked
? const Icon(Icons.favorite, color: Colors.redAccent,key: ValueKey<int>(0),)
: const Icon(Icons.favorite_border, key:ValueKey<int>(1),),
),
)
)
],
),
),
]),
),
);
}
}