145 lines
5.3 KiB
Dart
145 lines
5.3 KiB
Dart
part of "home_page.dart";
|
|
|
|
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
|
|
|
|
class _MarketCard extends StatefulWidget {
|
|
final String price;
|
|
final String name;
|
|
final String? discount;
|
|
final String size;
|
|
final String? image;
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const _MarketCard(this.price, this.name, this.discount, this.size,
|
|
{required this.image, this.onLike, this.onTap});
|
|
|
|
factory _MarketCard.formDate(MarketData date,
|
|
{OnLikeCallback? onLike, VoidCallback? onTap}) =>
|
|
_MarketCard(date.price, date.name, date.discount, date.size,
|
|
image: date.image, onLike: onLike, onTap: onTap);
|
|
|
|
@override
|
|
State<_MarketCard> createState() => _MarketCardState();
|
|
}
|
|
|
|
class _MarketCardState extends State<_MarketCard> {
|
|
bool isLiked = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: widget.onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.all(10),
|
|
margin: const EdgeInsets.all(4),
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFFE5E4E2),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: IntrinsicHeight(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: 160,
|
|
child: Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: Image.network(
|
|
widget.image ?? '',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFFffef42),
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(20),
|
|
)),
|
|
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
|
child: Text(
|
|
"новинка",
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium
|
|
?.copyWith(color: Colors.black),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
)),
|
|
),
|
|
Row(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
top: 6,
|
|
),
|
|
child: Text(
|
|
widget.discount ?? '',
|
|
style:
|
|
TextStyle(fontSize: 26, color: Color(0xFFF1571E)),
|
|
),
|
|
),
|
|
Text(
|
|
widget.price,
|
|
style: TextStyle(
|
|
fontSize: 16, decoration: TextDecoration.lineThrough),
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
widget.name,
|
|
style: TextStyle(fontSize: 20),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
widget.size,
|
|
style: TextStyle(fontSize: 18),
|
|
),
|
|
const Spacer(),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
isLiked = !isLiked;
|
|
});
|
|
widget.onLike?.call(widget.name, isLiked);
|
|
},
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 100),
|
|
child: isLiked
|
|
? const Icon(
|
|
Icons.favorite,
|
|
color: Colors.redAccent,
|
|
key: ValueKey<int>(0),
|
|
)
|
|
: const Icon(
|
|
Icons.favorite,
|
|
color: Colors.grey,
|
|
key: ValueKey<int>(1),
|
|
)),
|
|
)),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
)),
|
|
);
|
|
}
|
|
}
|