PMU-PIbd-31-Potapov-N-S/lib/presentation/home_page/card.dart

149 lines
4.5 KiB
Dart
Raw Normal View History

2024-12-19 13:20:27 +04:00
part of 'home_page.dart';
typedef OnLikeCallback = void Function(String title, bool isLiked)?;
const double NORMAL_ICON_SCALE = 2.0;
const double SCALED_ICON_SCALE = 2.5;
2024-12-19 13:20:27 +04:00
class _Card extends StatefulWidget {
2024-12-13 03:03:08 +04:00
final String? description;
final String? imageUrl;
2024-12-13 03:03:08 +04:00
final bool? isLiked;
final String? name;
final String? surname;
final OnLikeCallback onLike;
final VoidCallback? onTap;
2024-12-19 13:20:27 +04:00
const _Card(
2024-12-13 03:03:08 +04:00
{this.name,
this.surname,
this.description,
this.imageUrl,
this.isLiked,
this.onLike,
this.onTap});
2024-12-19 13:20:27 +04:00
factory _Card.fromData(CardData data,
{OnLikeCallback onLike, VoidCallback? onTap}) =>
2024-12-19 13:20:27 +04:00
_Card(
2024-12-13 03:03:08 +04:00
name: data.name,
surname: data.surname,
description: data.description,
imageUrl: data.imageUrl,
isLiked: data.isLiked,
onLike: onLike,
onTap: onTap);
@override
2024-12-19 13:20:27 +04:00
State<_Card> createState() => _CardState();
}
2024-12-19 13:20:27 +04:00
class _CardState extends State<_Card> {
bool isLiked = false;
double iconScale = NORMAL_ICON_SCALE;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
child: Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue,
border: Border.all(
color: Colors.blue,
width: 0.5,
),
boxShadow: const [
BoxShadow(
color: Colors.black12,
offset: Offset(
0.0,
5.0,
),
blurRadius: 4.0,
spreadRadius: 1.0,
),
],
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Text(
2024-12-13 03:03:08 +04:00
(widget.name ?? "") + (" ") + (widget.surname ?? ""),
style: const TextStyle(
color: Colors.white,
fontSize: 30,
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Text(
2024-12-13 03:03:08 +04:00
widget.description ?? "",
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
],
),
),
if (widget.imageUrl != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.network(widget.imageUrl!,
height: 500,
width: double.infinity,
fit: BoxFit.fitWidth),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () => {
setState(() {
isLiked = !isLiked;
2024-12-13 03:03:08 +04:00
widget.onLike?.call(widget.name ?? "", isLiked);
})
},
child: AnimatedScale(
scale: iconScale,
duration: const Duration(milliseconds: 250),
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: isLiked
? const Icon(
Icons.favorite,
color: Colors.red,
key: ValueKey(1),
)
: const Icon(Icons.favorite_border,
color: Colors.black, key: ValueKey(1)))),
),
],
),
)
],
),
));
}
}