PIbd-33_Radaev_A_V_PMD/lib/presentation/home_page/car.dart
2024-10-14 18:05:40 +04:00

131 lines
3.7 KiB
Dart

part of 'home_page.dart';
class _CarData {
final String text;
final String descriptionCar;
final IconData icon;
final String? imageUrl;
_CarData(
this.text, {
required this.descriptionCar,
this.icon = Icons.ac_unit_outlined,
this.imageUrl,
});
}
class _Car extends StatefulWidget {
final String text;
final String descriptionCar;
final IconData icon;
final String? imageUrl;
const _Car(
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionCar,
this.imageUrl,
});
factory _Car.fromData(_CarData data) => _Car(
data.text,
descriptionCar: data.descriptionCar,
icon: data.icon,
imageUrl: data.imageUrl,
);
@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;
});
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: islike
? const Icon(
Icons.add_circle_outline,
color: Colors.redAccent,
key: ValueKey<int>(0),
)
: const Icon(
Icons.add_circle,
key: ValueKey<int>(1),
),
),
),
),
),
],
),
)
);
}
}