2024-10-22 08:55:54 +04:00
|
|
|
part of 'home_page.dart';
|
|
|
|
|
2024-12-12 13:40:51 +04:00
|
|
|
typedef OnLikeCallBack = void Function(String? id, String title, bool isLiked)?;
|
2024-10-22 08:55:54 +04:00
|
|
|
|
2024-12-12 13:40:51 +04:00
|
|
|
class _Card extends StatelessWidget {
|
2024-10-22 08:55:54 +04:00
|
|
|
final String name;
|
|
|
|
final int age;
|
|
|
|
final List<String> courses;
|
|
|
|
final String? imageUrl;
|
|
|
|
final OnLikeCallBack onLike;
|
|
|
|
final VoidCallback? onTap;
|
2024-12-12 13:40:51 +04:00
|
|
|
final String? id;
|
|
|
|
final bool isLiked;
|
2024-10-22 08:55:54 +04:00
|
|
|
|
|
|
|
const _Card(
|
|
|
|
this.name, {
|
|
|
|
required this.age,
|
|
|
|
required this.courses,
|
|
|
|
this.imageUrl,
|
|
|
|
this.onLike,
|
|
|
|
this.onTap,
|
2024-12-12 13:40:51 +04:00
|
|
|
this.id,
|
|
|
|
this.isLiked = false,
|
2024-10-22 08:55:54 +04:00
|
|
|
});
|
|
|
|
|
2024-12-12 13:40:51 +04:00
|
|
|
factory _Card.fromData(Student data,
|
|
|
|
{OnLikeCallBack onLike, VoidCallback? onTap, bool isLiked = false}) =>
|
|
|
|
_Card(
|
2024-10-22 08:55:54 +04:00
|
|
|
data.name,
|
|
|
|
age: data.age,
|
|
|
|
courses: data.courses,
|
|
|
|
imageUrl: data.image,
|
|
|
|
onLike: onLike,
|
|
|
|
onTap: onTap,
|
2024-12-12 13:40:51 +04:00
|
|
|
isLiked: isLiked,
|
|
|
|
id: data.id,
|
2024-10-22 08:55:54 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
2024-12-12 13:40:51 +04:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.only(top: 16, left: 16, right: 16, bottom: 16),
|
|
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.blueAccent,
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.black.withOpacity(0.2),
|
|
|
|
spreadRadius: 2,
|
|
|
|
blurRadius: 5,
|
|
|
|
offset: Offset(0, 3),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 8.0,
|
|
|
|
right: 16,
|
|
|
|
bottom: 16,
|
|
|
|
),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => onLike?.call(id, name, isLiked),
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
child: isLiked
|
|
|
|
? const Icon(
|
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.lightBlueAccent,
|
|
|
|
key: ValueKey<int>(0),
|
|
|
|
)
|
|
|
|
: const Icon(Icons.favorite_border),
|
|
|
|
key: ValueKey<int>(0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 16),
|
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(name, style: Theme.of(context).textTheme.bodyLarge),
|
|
|
|
SizedBox(height: 12),
|
|
|
|
Text('Age: ${Student.getYearWord(age)}',
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge),
|
|
|
|
SizedBox(height: 12),
|
|
|
|
Text('Courses: ${courses.join(", ")}',
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomRight: Radius.circular(20),
|
|
|
|
topRight: Radius.circular(20),
|
|
|
|
),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Positioned.fill(
|
|
|
|
child: Image.network(
|
|
|
|
imageUrl ?? '',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)));
|
|
|
|
}
|
2024-10-22 08:55:54 +04:00
|
|
|
}
|