import 'package:flutter/material.dart'; import '../data/bible.dart'; import 'progress_bar.dart'; import 'theme.dart'; class BookTile extends StatelessWidget { const BookTile({ super.key, required this.book, required this.chaptersRead, required this.accent, required this.onTap, }); final Book book; final int chaptersRead; final Color accent; final VoidCallback onTap; @override Widget build(BuildContext context) { final bool complete = chaptersRead == book.chapterCount; final bool started = chaptersRead > 0 && !complete; final double fraction = book.chapterCount == 0 ? 0 : chaptersRead / book.chapterCount; Color leadingColor; IconData? leadingIcon; if (complete) { leadingColor = accent; leadingIcon = Icons.check_rounded; } else if (started) { leadingColor = accent.withValues(alpha: 0.6); leadingIcon = null; } else { leadingColor = Theme.of(context).colorScheme.surfaceContainerHighest; leadingIcon = null; } return ListTile( onTap: onTap, leading: Container( width: 32, height: 32, decoration: BoxDecoration(color: leadingColor, shape: BoxShape.circle), alignment: Alignment.center, child: leadingIcon != null ? Icon(leadingIcon, size: 18, color: Colors.white) : Text( '${book.chapterCount}', style: Theme.of(context).textTheme.labelMedium?.copyWith( color: started ? Colors.white : Theme.of(context).colorScheme.onSurfaceVariant, fontWeight: FontWeight.w600, ), ), ), title: Text( book.name, style: Theme.of( context, ).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w500), ), subtitle: Padding( padding: const EdgeInsets.only(top: AppTokens.spaceXS), child: Row( children: [ Expanded( child: ProgressBar(value: fraction, color: accent, height: 4), ), const SizedBox(width: AppTokens.spaceM), Text( '$chaptersRead / ${book.chapterCount}', style: Theme.of(context).textTheme.labelSmall?.copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, ), ), ], ), ), ); } }