141 lines
4.2 KiB
Dart
141 lines
4.2 KiB
Dart
part of 'home_page.dart';
|
|
|
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|
|
|
const double NORMAL_ICON_SCALE = 2.0;
|
|
const double SCALED_ICON_SCALE = 2.5;
|
|
|
|
class _Card extends StatelessWidget {
|
|
final String? description;
|
|
final String? imageUrl;
|
|
final bool isLiked;
|
|
final String? id;
|
|
final String? name;
|
|
final String? surname;
|
|
|
|
final OnLikeCallback onLike;
|
|
final VoidCallback? onTap;
|
|
|
|
const _Card(
|
|
{this.name,
|
|
this.surname,
|
|
this.description,
|
|
this.imageUrl,
|
|
this.isLiked = false,
|
|
this.onLike,
|
|
this.onTap,
|
|
this.id});
|
|
|
|
factory _Card.fromData(CardData data,
|
|
{OnLikeCallback onLike, VoidCallback? onTap, bool isLiked = false}) =>
|
|
_Card(
|
|
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(
|
|
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(
|
|
(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(
|
|
description ?? "",
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (imageUrl != null)
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Image.network(imageUrl!,
|
|
height: 500,
|
|
width: double.infinity,
|
|
fit: BoxFit.fitWidth),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(4.0),
|
|
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => onLike?.call(id, "${name!} ${surname!}", isLiked),
|
|
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),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
));
|
|
}
|
|
}
|