PIbd-31_Belianin_N._N._PMD/lib/home_page/card.dart

111 lines
3.6 KiB
Dart
Raw Normal View History

2024-09-20 16:16:06 +04:00
part of "home_page.dart";
typedef OnLikeFunction = void Function(String text);
class _Card extends StatefulWidget {
final String name;
final String location;
final String image;
final String description;
final OnLikeFunction? onLike;
final VoidCallback? onTap;
const _Card(
{required this.name, required this.location, required this.image, required this.description, required this.onLike, required this.onTap});
2024-09-30 04:34:25 +04:00
factory _Card.fromData(CardData data, {OnLikeFunction? onLike, VoidCallback? onTap}) =>
2024-09-20 16:16:06 +04:00
_Card(
name: data.name,
location: data.location,
image: data.image,
description: data.description,
onLike: onLike,
onTap: onTap);
@override
State<StatefulWidget> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool _isFavourite = false;
void toggleIsFavourite() {
setState(() {
_isFavourite = !_isFavourite;
});
widget.onLike?.call(_isFavourite
? "Property liked me"
: "Property has been removed from the likes");
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
child: Container(
width: double.infinity,
padding:
const EdgeInsets.only(top: 15, bottom: 15, left: 30, right: 30),
decoration: BoxDecoration(
border: Border.all(color: Colors.black12, width: 2),
color: Colors.blue,
borderRadius: BorderRadius.circular(20)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start, // Выравниваем по левому краю
children: [
GestureDetector(
onTap: toggleIsFavourite,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: _isFavourite
? const Icon(
Icons.favorite,
color: Colors.red,
key: ValueKey<int>(0),
)
: const Icon(
Icons.favorite_border,
color: Colors.red,
key: ValueKey<int>(1),
),
),
)
],
),
const SizedBox(height: 20),
Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
// Радиус скругления
child: Image.network(
widget.image,
width: 280, // Ширина изображения
height: 350, // Высота изображения
fit: BoxFit.cover
)// Позволяет изображению подстраиваться под рамки),
),
),
Padding(
padding: const EdgeInsets.only(top: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.name, style: TextStyle(fontSize: 17)),
Text("Местоположение: ${widget.location}",
style: TextStyle(fontSize: 15)),
Text("${widget.description}",
style: TextStyle(fontSize: 17, color: Colors.orange))
],
),
)
],
),
),
);
}
}