2024-11-08 13:07:43 +04:00
|
|
|
part of 'home_page.dart';
|
|
|
|
|
2024-12-10 20:49:23 +04:00
|
|
|
typedef onLikeCallback = void Function(String id, String title, bool isLiked)?;
|
|
|
|
|
|
|
|
class _Card extends StatelessWidget {
|
|
|
|
final String title;
|
|
|
|
final String artist;
|
|
|
|
final String year;
|
|
|
|
final List<String> genres;
|
|
|
|
final String? imageUrl;
|
|
|
|
final onLikeCallback onLike;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
final String id;
|
|
|
|
final bool isLiked;
|
|
|
|
|
|
|
|
const _Card(
|
|
|
|
this.title, {
|
|
|
|
required this.artist,
|
|
|
|
required this.year,
|
|
|
|
required this.genres,
|
|
|
|
this.imageUrl,
|
|
|
|
this.onLike,
|
|
|
|
this.onTap,
|
|
|
|
required this.id,
|
|
|
|
this.isLiked = false,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory _Card.fromData(
|
|
|
|
CardData data, {
|
|
|
|
onLikeCallback onLike,
|
|
|
|
VoidCallback? onTap,
|
|
|
|
bool isLiked = false,
|
|
|
|
}) =>
|
|
|
|
_Card(
|
|
|
|
data.title,
|
|
|
|
artist: data.artist,
|
|
|
|
year: data.year,
|
|
|
|
genres: data.genres,
|
|
|
|
imageUrl: data.imageUrl,
|
|
|
|
onLike: onLike,
|
|
|
|
onTap: onTap,
|
|
|
|
id: data.id,
|
|
|
|
isLiked: isLiked,
|
|
|
|
);
|
2024-11-08 13:07:43 +04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
2024-12-10 20:49:23 +04:00
|
|
|
onTap: onTap,
|
2024-11-08 13:07:43 +04:00
|
|
|
child: Container(
|
2024-12-10 20:49:23 +04:00
|
|
|
margin: const EdgeInsets.only(top: 16, left: 5, right: 5),
|
|
|
|
constraints: const BoxConstraints(minHeight: 140),
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: const Color(0xFF231a24),
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.orange,
|
|
|
|
width: 6,
|
2024-11-08 13:07:43 +04:00
|
|
|
),
|
2024-12-10 20:49:23 +04:00
|
|
|
),
|
2024-11-08 13:07:43 +04:00
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
child: SizedBox(
|
|
|
|
width: 140,
|
|
|
|
height: 100,
|
|
|
|
child: Image.network(
|
2024-12-10 20:49:23 +04:00
|
|
|
imageUrl ?? '',
|
2024-11-08 13:07:43 +04:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-12-10 20:49:23 +04:00
|
|
|
Expanded(
|
2024-11-08 13:07:43 +04:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
|
|
child: Column(
|
2024-12-10 20:49:23 +04:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-11-08 13:07:43 +04:00
|
|
|
children: [
|
|
|
|
Text(
|
2024-12-10 20:49:23 +04:00
|
|
|
title,
|
2024-11-08 13:07:43 +04:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
2024-12-10 20:49:23 +04:00
|
|
|
.headlineSmall
|
|
|
|
?.copyWith(color: Colors.orange),
|
2024-11-08 13:07:43 +04:00
|
|
|
),
|
|
|
|
Text(
|
2024-12-10 20:49:23 +04:00
|
|
|
artist,
|
2024-11-08 13:07:43 +04:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium
|
2024-12-10 20:49:23 +04:00
|
|
|
?.copyWith(color: Color(0xFFDCDCDC)),
|
|
|
|
),
|
|
|
|
// Здесь можно добавить отображение года и жанров, если это необходимо
|
|
|
|
Text(
|
|
|
|
year,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
genres.join(', '),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
2024-11-08 13:07:43 +04:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0, right: 16, bottom: 16),
|
|
|
|
child: GestureDetector(
|
2024-12-10 20:49:23 +04:00
|
|
|
onTap: () => onLike?.call(id, title, isLiked),
|
2024-11-08 13:07:43 +04:00
|
|
|
child: AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
child: isLiked
|
|
|
|
? const Icon(
|
2024-12-10 20:49:23 +04:00
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.redAccent,
|
|
|
|
key: ValueKey<int>(0),
|
|
|
|
)
|
2024-11-08 13:07:43 +04:00
|
|
|
: const Icon(
|
2024-12-10 20:49:23 +04:00
|
|
|
Icons.favorite_border,
|
|
|
|
color: Colors.purple,
|
|
|
|
key: ValueKey<int>(1),
|
|
|
|
),
|
2024-11-08 13:07:43 +04:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|