101 lines
2.9 KiB
Dart
101 lines
2.9 KiB
Dart
part of "home_page.dart";
|
||
|
||
typedef OnLikeFunction = void Function(String text);
|
||
|
||
class _Card extends StatefulWidget {
|
||
final String name;
|
||
final double price;
|
||
|
||
final OnLikeFunction? onLike;
|
||
final VoidCallback? onTap;
|
||
|
||
const _Card(
|
||
{required this.name, required this.price, this.onLike, this.onTap});
|
||
|
||
factory _Card.fromData(
|
||
CardData data, OnLikeFunction? onLike, VoidCallback? onTap) =>
|
||
_Card(
|
||
name: data.name,
|
||
price: data.price,
|
||
onTap: onTap,
|
||
onLike: onLike,
|
||
);
|
||
|
||
@override
|
||
State<StatefulWidget> createState() => _CardState();
|
||
}
|
||
|
||
class _CardState extends State<_Card> {
|
||
bool _isFavourite = false;
|
||
|
||
void toggleIsFavourite() {
|
||
setState(() {
|
||
_isFavourite = !_isFavourite;
|
||
});
|
||
widget.onLike?.call(_isFavourite
|
||
? "Product added in favourite"
|
||
: "Product deleted from favourite");
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return GestureDetector(
|
||
onTap: widget.onTap,
|
||
child: Container(
|
||
width: double.infinity,
|
||
padding:
|
||
const EdgeInsets.only(top: 15, bottom: 15, left: 30, right: 30),
|
||
decoration: BoxDecoration(
|
||
border: Border.all(color: Colors.black12, width: 2),
|
||
borderRadius: BorderRadius.circular(20)),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.end,
|
||
children: [
|
||
GestureDetector(
|
||
onTap: toggleIsFavourite,
|
||
child: AnimatedSwitcher(
|
||
duration: const Duration(milliseconds: 200),
|
||
child: _isFavourite
|
||
? const Icon(
|
||
Icons.favorite,
|
||
color: Colors.red,
|
||
key: ValueKey<int>(0),
|
||
)
|
||
: const Icon(
|
||
Icons.favorite_border,
|
||
color: Colors.red,
|
||
key: ValueKey<int>(1),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
Center(
|
||
child: Image.network(
|
||
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtAT11wKgHrJBUYzIBFogucXg0a9fE0fQXDQ&s",
|
||
height: 250,
|
||
width: 250,
|
||
),
|
||
),
|
||
Padding(
|
||
padding: const EdgeInsets.only(top: 50),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(widget.name, style: const TextStyle(fontSize: 17)),
|
||
Text("${widget.price} Руб",
|
||
style:
|
||
const TextStyle(fontSize: 17, color: Colors.orange))
|
||
],
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|