168 lines
5.5 KiB
Dart
Raw Permalink Normal View History

2024-10-14 18:05:40 +04:00
part of 'home_page.dart';
2024-12-12 14:21:13 +04:00
2024-12-11 13:10:34 +04:00
// Ctrl+Alt+L
2024-10-23 16:00:47 +04:00
typedef OnLikeCallback = void Function(String title, bool isLike)?;
2024-10-14 18:05:40 +04:00
class _Car extends StatefulWidget {
final String text;
final String descriptionCar;
final IconData icon;
final String? imageUrl;
2024-10-23 16:00:47 +04:00
final OnLikeCallback onLike;
2024-12-11 13:10:34 +04:00
final VoidCallback? onTap;
2024-10-14 18:05:40 +04:00
const _Car(
2024-10-23 16:00:47 +04:00
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionCar,
this.imageUrl,
this.onLike,
2024-12-11 13:10:34 +04:00
this.onTap,
2024-10-23 16:00:47 +04:00
});
2024-10-14 18:05:40 +04:00
2024-10-23 16:00:47 +04:00
factory _Car.fromData(
CarData data, {
OnLikeCallback onLike,
2024-12-11 13:10:34 +04:00
VoidCallback? onTap,
2024-10-23 16:00:47 +04:00
}) =>
_Car(
data.text,
descriptionCar: data.descriptionCar,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
2024-12-11 13:10:34 +04:00
onTap: onTap,
2024-10-23 16:00:47 +04:00
);
2024-10-14 18:05:40 +04:00
@override
State<_Car> createState() => _CarState();
}
class _CarState extends State<_Car> {
bool islike = false;
@override
Widget build(BuildContext context) {
2024-12-11 13:10:34 +04:00
return GestureDetector(
onTap: widget.onTap,
child: Container(
2024-10-14 18:05:40 +04:00
margin: const EdgeInsets.all(16),
2024-12-11 13:10:34 +04:00
constraints: const BoxConstraints(minHeight: 160),
2024-10-14 18:05:40 +04:00
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
2024-12-12 13:37:32 +04:00
color: Colors.deepPurple.withOpacity(.4),
2024-12-11 13:10:34 +04:00
spreadRadius: 4,
2024-12-12 13:37:32 +04:00
offset: const Offset(0, 0),
2024-10-14 18:05:40 +04:00
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
2024-12-12 14:21:13 +04:00
height: 160,
2024-10-14 18:05:40 +04:00
width: 150,
child: Image.network(
widget.imageUrl ?? '',
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,
2024-12-12 14:21:13 +04:00
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
2024-10-14 18:05:40 +04:00
),
Text(
widget.descriptionCar,
2024-12-12 14:21:13 +04:00
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.normal),
),
const SizedBox(height: 8),
// Отступ между текстом и виджетом со скидкой
Align(
alignment: Alignment.bottomLeft,
child: Container(
decoration: const BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.account_balance_wallet,
// Иконка со скидкой
color: Colors.black,
),
const SizedBox(width: 4),
// Пробел между иконкой и текстом
Text(
'Exclusive!',
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: Colors.black),
),
],
),
),
),
2024-10-14 18:05:40 +04:00
],
),
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8,
right: 16,
bottom: 16,
),
child: GestureDetector(
onTap: () {
2024-10-23 16:00:47 +04:00
setState(() => islike = !islike);
widget.onLike?.call(widget.text, islike);
2024-10-14 18:05:40 +04:00
},
child: AnimatedSwitcher(
2024-10-23 16:00:47 +04:00
duration: const Duration(milliseconds: 400),
2024-10-14 18:05:40 +04:00
child: islike
? const Icon(
2024-10-23 16:00:47 +04:00
Icons.add_circle,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
2024-10-14 18:05:40 +04:00
: const Icon(
2024-10-23 16:00:47 +04:00
Icons.add_circle_outline,
key: ValueKey<int>(1),
),
2024-10-14 18:05:40 +04:00
),
),
),
),
],
),
2024-12-11 13:10:34 +04:00
),
),
);
2024-10-14 18:05:40 +04:00
}
2024-10-23 16:00:47 +04:00
}