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

141 lines
4.2 KiB
Dart
Raw Normal View History

2024-12-19 13:20:27 +04:00
part of 'home_page.dart';
2024-12-19 18:44:53 +04:00
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
const double NORMAL_ICON_SCALE = 2.0;
const double SCALED_ICON_SCALE = 2.5;
2024-12-19 18:44:53 +04:00
class _Card extends StatelessWidget {
2024-12-13 03:03:08 +04:00
final String? description;
final String? imageUrl;
2024-12-19 18:44:53 +04:00
final bool isLiked;
final String? id;
2024-12-13 03:03:08 +04:00
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,
2024-12-19 18:44:53 +04:00
this.isLiked = false,
2024-12-13 03:03:08 +04:00
this.onLike,
2024-12-19 18:44:53 +04:00
this.onTap,
this.id});
2024-12-19 13:20:27 +04:00
factory _Card.fromData(CardData data,
2024-12-19 18:44:53 +04:00
{OnLikeCallback onLike, VoidCallback? onTap, bool isLiked = false}) =>
2024-12-19 13:20:27 +04:00
_Card(
2024-12-19 18:44:53 +04:00
name: data.name,
surname: data.surname,
description: data.description,
imageUrl: data.imageUrl,
isLiked: isLiked,
onLike: onLike,
onTap: onTap,
id: data.id,
);
@override
Widget build(BuildContext context) {
return GestureDetector(
2024-12-19 18:44:53 +04:00
onTap: 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-19 18:44:53 +04:00
(name ?? "") + (" ") + (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-19 18:44:53 +04:00
description ?? "",
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
],
),
),
2024-12-19 18:44:53 +04:00
if (imageUrl != null)
Padding(
padding: const EdgeInsets.all(8.0),
2024-12-19 18:44:53 +04:00
child: Image.network(imageUrl!,
height: 500,
width: double.infinity,
fit: BoxFit.fitWidth),
),
Padding(
padding: const EdgeInsets.all(4.0),
2024-12-19 18:44:53 +04:00
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () => onLike?.call(id, "${name!} ${surname!}", isLiked),
2024-12-19 18:44:53 +04:00
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: !isLiked
? const Icon(
Icons.favorite_border,
color: Colors.black,
key: ValueKey<int>(0),
)
: const Icon(
Icons.favorite,
color: Colors.red,
key: ValueKey<int>(1),
),
),
),
],
),
2024-12-19 18:44:53 +04:00
),
],
),
));
}
}