123 lines
3.8 KiB
Dart
123 lines
3.8 KiB
Dart
part of '../../Presentation/home_page/home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
class CardData {
|
|
final String text;
|
|
final String info;
|
|
final String? urlImage;
|
|
|
|
CardData({required this.text, required this.info, required this.urlImage});
|
|
}
|
|
|
|
class MyCard extends StatefulWidget {
|
|
final String text;
|
|
final String info;
|
|
final String? urlImage;
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const MyCard({super.key, required this.text, required this.info, required this.urlImage, this.onLike, this.onTap});
|
|
|
|
factory MyCard.fromData(CardData data, {OnLikeCallback onLike, VoidCallback? onTap}) => MyCard(
|
|
text: data.text,
|
|
info: data.info,
|
|
urlImage: data.urlImage,
|
|
onLike: onLike,
|
|
onTap: onTap,
|
|
);
|
|
|
|
@override
|
|
State<MyCard> createState() => _MyCardState();
|
|
}
|
|
|
|
class _MyCardState extends State<MyCard> {
|
|
bool isLiked = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: widget.onTap,
|
|
child: Container(
|
|
margin: const EdgeInsets.all(16),
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white70,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: Colors.grey.shade200),
|
|
),
|
|
child: IntrinsicHeight(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(20),
|
|
topLeft: Radius.circular(20),
|
|
),
|
|
child: SizedBox(
|
|
height: double.infinity,
|
|
width: 160,
|
|
child: Image.network(
|
|
widget.urlImage ?? 'https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
widget.text,
|
|
style: Theme.of(context).textTheme.headlineLarge,
|
|
),
|
|
Text(
|
|
widget.info,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
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.favorite,
|
|
color: Colors.redAccent,
|
|
key: ValueKey<int>(0),
|
|
)
|
|
: const Icon(
|
|
Icons.favorite_border,
|
|
key: ValueKey<int>(1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |