import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import '../../models/album.dart'; import '../../shared/widgets/server_image.dart'; import '../../theme/theme_extension.dart'; class AlbumCard extends StatelessWidget { const AlbumCard({ required this.album, required this.onTap, this.width = 140, this.titleMaxLines = 1, this.showArtist = true, super.key, }); final AlbumRef album; final VoidCallback onTap; /// Outer width of the card. Cover is square at width - 16 (8dp /// horizontal padding either side). Default suits horizontal lists; /// grids should pass the cell width so the card scales down. final double width; /// Lets callers (e.g. the artist detail grid) allow the title to /// wrap to a second line so it isn't truncated to a single /// ellipsized character at narrower widths. final int titleMaxLines; /// Suppress the artist name. Useful on surfaces where the artist is /// already implied by the page header (e.g. artist detail). final bool showArtist; @override Widget build(BuildContext context) { final fs = Theme.of(context).extension()!; final coverSize = width - 16; return SizedBox( width: width, child: Material( color: Colors.transparent, child: InkWell( onTap: onTap, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ ClipRRect( borderRadius: BorderRadius.circular(6), child: Container( width: coverSize, height: coverSize, color: fs.slate, child: album.coverUrl.isEmpty ? SvgPicture.asset('assets/svg/album-fallback.svg', fit: BoxFit.cover) : ServerImage(url: album.coverUrl, fit: BoxFit.cover), ), ), const SizedBox(height: 8), Text( album.title, maxLines: titleMaxLines, overflow: TextOverflow.ellipsis, style: TextStyle(color: fs.parchment, fontSize: 14), ), if (showArtist && album.artistName.isNotEmpty) Text( album.artistName, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: fs.ash, fontSize: 12), ), ], ), ), ), ), ); } }