part of 'home_page.dart'; class _CardState extends State<_Card> { bool isLiked = false; @override Widget build(BuildContext context) { return GestureDetector( onTap: widget.onTap, child: Container( 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, ), ), 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( widget.imageUrl ?? '', fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Placeholder(), ), ), ), Flexible( child: Padding( padding: const EdgeInsets.only(left: 16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( widget.title, style: Theme.of(context) .textTheme .headlineLarge ?.copyWith(color: Colors.orange), // Грязно-белый цвет ), Text( widget.artist, style: Theme.of(context) .textTheme .bodyMedium ?.copyWith(color: Color(0xFFDCDCDC)), // Грязно-белый цвет ), ], ), ), ), Padding( padding: const EdgeInsets.only(left: 8.0, right: 16, bottom: 16), child: GestureDetector( onTap: () { setState(() { isLiked = !isLiked; }); widget.onLike?.call(widget.title, isLiked); }, child: AnimatedSwitcher( duration: const Duration(milliseconds: 300), child: isLiked ? const Icon( Icons.favorite, color: Colors.pink, key: ValueKey(0), ) : const Icon( Icons.favorite_border_outlined, color: Colors.purple), key: ValueKey(1), ), ), ) ], ), ), ), ); } } typedef onLikeCallback = void Function(String title, bool isLiked)?; class _Card extends StatefulWidget { final String title; final String artist; final String year; final List genres; final String? imageUrl; final onLikeCallback onLike; final VoidCallback? onTap; const _Card(this.title, {required this.artist, required this.year, required this.genres, this.imageUrl, this.onLike, this.onTap}); factory _Card.fromData(CardData data, {onLikeCallback? onLike, VoidCallback? onTap}) { // Инициализация изображений альбома AlbumDataImagesJPGDto imagesJPGDto = AlbumDataImagesJPGDto( image_url: data.imageUrl, // Это URL изображений ); AlbumDataImagesDto imagesDto = AlbumDataImagesDto( jpg: imagesJPGDto, ); // Создаем DTO альбома AlbumDataDto albumDto = AlbumDataDto( title: data.title, artist: data.artist, images: imagesDto, ); // Предполагается, что year и genres уже есть в data return _Card( albumDto.title ?? 'UNKNOWN', artist: albumDto.artist ?? 'UNKNOWN', year: data.year, genres: data.genres, imageUrl: data.imageUrl, onLike: onLike, onTap: onTap, ); } @override State<_Card> createState() => _CardState(); }