PIbd-33_Radaev_A_V_PMD/lib/presentation/home_page/car.dart
Arkadiy Radaev e5790081f0 lab 5 start
2024-10-28 16:20:50 +04:00

125 lines
3.7 KiB
Dart

part of 'home_page.dart';
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;
const _Car(
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionCar,
this.imageUrl,
this.onLike,
});
factory _Car.fromData(
CarData data, {
OnLikeCallback onLike,
}) =>
_Car(
data.text,
descriptionCar: data.descriptionCar,
icon: data.icon,
imageUrl: data.imageUrl,
onLike: onLike,
);
@override
State<_Car> createState() => _CarState();
}
class _CarState extends State<_Car> {
bool islike = false;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.redAccent),
boxShadow: [
BoxShadow(
color: Colors.deepOrange.withOpacity(.5),
spreadRadius: 5,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 150,
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: Theme.of(context).textTheme.headlineLarge,
),
Text(
widget.descriptionCar,
style: Theme.of(context).textTheme.bodyLarge,
)
],
),
),
),
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),
),
),
),
),
),
],
),
));
}
}