2024-12-12 14:21:13 +04:00

168 lines
5.5 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

part of 'home_page.dart';
// Ctrl+Alt+L
typedef OnLikeCallback = void Function(String title, bool isLike)?;
class _Car extends StatefulWidget {
final String text;
final String descriptionCar;
final IconData icon;
final String? imageUrl;
final OnLikeCallback onLike;
final VoidCallback? onTap;
const _Car(
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionCar,
this.imageUrl,
this.onLike,
this.onTap,
});
factory _Car.fromData(
CarData data, {
OnLikeCallback onLike,
VoidCallback? onTap,
}) =>
_Car(
data.text,
descriptionCar: data.descriptionCar,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
onTap: onTap,
);
@override
State<_Car> createState() => _CarState();
}
class _CarState extends State<_Car> {
bool islike = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
child: Container(
margin: const EdgeInsets.all(16),
constraints: const BoxConstraints(minHeight: 160),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.deepPurple.withOpacity(.4),
spreadRadius: 4,
offset: const Offset(0, 0),
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 160,
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,
style: const TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
Text(
widget.descriptionCar,
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),
),
],
),
),
),
],
),
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8,
right: 16,
bottom: 16,
),
child: GestureDetector(
onTap: () {
setState(() => islike = !islike);
widget.onLike?.call(widget.text, islike);
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
child: islike
? const Icon(
Icons.add_circle,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
: const Icon(
Icons.add_circle_outline,
key: ValueKey<int>(1),
),
),
),
),
),
],
),
),
),
);
}
}