Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Playlist/collection sheets: card-style covers, overlays, multi-select

Nathan Poulsonf8b67d158236
diff --git a/lib/widgets/collection_detail_sheet.dart b/lib/widgets/collection_detail_sheet.dart
index aba382f2..562e7a86 100644
--- a/lib/widgets/collection_detail_sheet.dart
+++ b/lib/widgets/collection_detail_sheet.dart
@@ -2,8 +2,10 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
+import 'package:cached_network_image/cached_network_image.dart';
import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
+import '../services/download_service.dart';
import 'book_detail_sheet.dart';
class CollectionDetailSheet extends StatefulWidget {
@@ -221,7 +223,7 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
Widget _buildReorderList(ColorScheme cs, TextTheme tt, LibraryProvider lib) {
final items = _reorderItems!;
return ReorderableListView.builder(
- padding: const EdgeInsets.symmetric(vertical: 8),
+ padding: EdgeInsets.only(top: 8, bottom: 8 + MediaQuery.of(context).viewPadding.bottom),
onReorderStart: (_) => HapticFeedback.mediumImpact(),
onReorder: (oldIndex, newIndex) {
setState(() {
@@ -284,9 +286,12 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
}
Widget _buildItemList(ColorScheme cs, TextTheme tt, LibraryProvider lib, List<dynamic> books, {required bool isRoot}) {
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final doneColor = isDark ? Colors.greenAccent[400]! : Colors.green.shade700;
+
return ListView.builder(
controller: widget.scrollController,
- padding: const EdgeInsets.only(bottom: 40),
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4).copyWith(bottom: 40),
itemCount: books.length,
itemBuilder: (context, index) {
final book = books[index] as Map<String, dynamic>;
@@ -296,39 +301,107 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
final title = metadata['title'] as String? ?? 'Unknown';
final author = metadata['authorName'] as String? ?? '';
final coverUrl = lib.getCoverUrl(itemId);
+ final progress = lib.getProgress(itemId);
+ final isFinished = lib.getProgressData(itemId)?['isFinished'] == true;
+ final isDownloaded = DownloadService().isDownloaded(itemId);
- final tile = ListTile(
- contentPadding: const EdgeInsets.symmetric(horizontal: 20),
- leading: SizedBox(
- width: 44, height: 44,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(6),
- child: coverUrl != null
- ? (coverUrl.startsWith('/')
- ? Image.file(File(coverUrl), fit: BoxFit.cover,
- errorBuilder: (_, __, ___) => _placeholder(cs))
- : Image.network(coverUrl, fit: BoxFit.cover,
- headers: lib.mediaHeaders,
- errorBuilder: (_, __, ___) => _placeholder(cs)))
- : _placeholder(cs),
- ),
- ),
- title: Text(
- title,
- maxLines: 1, overflow: TextOverflow.ellipsis,
- style: tt.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500, color: cs.onSurface,
+ final card = Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Card(
+ elevation: 0,
+ color: cs.surfaceContainerHigh,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
+ clipBehavior: Clip.antiAlias,
+ child: InkWell(
+ onTap: () => showBookDetailSheet(context, itemId),
+ borderRadius: BorderRadius.circular(14),
+ child: SizedBox(
+ height: 112,
+ child: Row(children: [
+ AspectRatio(
+ aspectRatio: 1,
+ child: Stack(children: [
+ Positioned.fill(
+ child: coverUrl != null
+ ? (coverUrl.startsWith('/')
+ ? Image.file(File(coverUrl), fit: BoxFit.cover,
+ errorBuilder: (_, __, ___) => _placeholder(cs))
+ : CachedNetworkImage(
+ imageUrl: coverUrl, fit: BoxFit.cover,
+ httpHeaders: lib.mediaHeaders,
+ placeholder: (_, __) => _placeholder(cs),
+ errorWidget: (_, __, ___) => _placeholder(cs),
+ ))
+ : _placeholder(cs),
+ ),
+ if (progress > 0 && !isFinished)
+ Positioned(
+ left: 0, right: 0, bottom: 0,
+ child: LinearProgressIndicator(
+ value: progress.clamp(0.0, 1.0),
+ minHeight: 3,
+ backgroundColor: Colors.black38,
+ valueColor: AlwaysStoppedAnimation(cs.primary),
+ ),
+ ),
+ if (isFinished || isDownloaded)
+ Positioned(
+ left: 0, right: 0, bottom: 0,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.bottomCenter,
+ end: Alignment.topCenter,
+ colors: [
+ Colors.black.withValues(alpha: 0.85),
+ Colors.black.withValues(alpha: 0.0),
+ ],
+ ),
+ ),
+ child: Column(mainAxisSize: MainAxisSize.min, children: [
+ if (isFinished)
+ Row(mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [
+ Icon(Icons.check_circle_rounded, size: 10, color: doneColor),
+ const SizedBox(width: 3),
+ Text('Done', style: TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: doneColor)),
+ ]),
+ if (isDownloaded)
+ Row(mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [
+ Icon(Icons.download_done_rounded, size: 10, color: cs.primary),
+ const SizedBox(width: 3),
+ Text('Saved', style: TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: cs.primary)),
+ ]),
+ ]),
+ ),
+ ),
+ ]),
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(title,
+ maxLines: 2, overflow: TextOverflow.ellipsis,
+ style: tt.bodyMedium?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface)),
+ const SizedBox(height: 4),
+ Text(author,
+ maxLines: 1, overflow: TextOverflow.ellipsis,
+ style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant)),
+ ],
+ ),
+ ),
+ ),
+ ]),
),
),
- subtitle: Text(
- author,
- maxLines: 1, overflow: TextOverflow.ellipsis,
- style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant),
- ),
- onTap: () => showBookDetailSheet(context, itemId),
- );
+ ),
+ );
- if (!isRoot) return tile;
+ if (!isRoot) return card;
return Dismissible(
key: ValueKey(itemId),
@@ -340,7 +413,7 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
color: cs.error.withValues(alpha: 0.1),
child: Icon(Icons.delete_rounded, color: cs.error),
),
- child: tile,
+ child: card,
);
},
);
diff --git a/lib/widgets/playlist_detail_sheet.dart b/lib/widgets/playlist_detail_sheet.dart
index be2e9cf8..7ae4d19e 100644
--- a/lib/widgets/playlist_detail_sheet.dart
+++ b/lib/widgets/playlist_detail_sheet.dart
@@ -2,7 +2,10 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
+import 'package:cached_network_image/cached_network_image.dart';
+import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
+import '../services/download_service.dart';
import 'book_detail_sheet.dart';
import 'episode_list_sheet.dart';
@@ -59,6 +62,114 @@ class PlaylistDetailSheet extends StatefulWidget {
class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
bool _reordering = false;
List<Map<String, dynamic>>? _reorderItems;
+ bool _selectMode = false;
+ final Set<String> _selectedKeys = {}; // "libraryItemId" or "libraryItemId-episodeId"
+ bool _isBatchUpdating = false;
+
+ String _itemKey(Map<String, dynamic> item) {
+ final libraryItemId = item['libraryItemId'] as String? ?? '';
+ final episodeId = item['episodeId'] as String?;
+ return episodeId != null ? '$libraryItemId-$episodeId' : libraryItemId;
+ }
+
+ Future<void> _batchMarkFinished(bool finished, LibraryProvider lib) async {
+ if (_selectedKeys.isEmpty) return;
+ final api = context.read<AuthProvider>().apiService;
+ if (api == null) return;
+
+ setState(() => _isBatchUpdating = true);
+
+ final playlist = lib.playlists.cast<Map<String, dynamic>>().where(
+ (p) => p['id'] == widget.playlistId,
+ ).firstOrNull;
+ final items = (playlist?['items'] as List<dynamic>?) ?? [];
+
+ for (final key in List<String>.from(_selectedKeys)) {
+ final item = items.cast<Map<String, dynamic>>().where(
+ (i) => _itemKey(i) == key,
+ ).firstOrNull;
+ if (item == null) continue;
+
+ final libraryItemId = item['libraryItemId'] as String? ?? '';
+ final episodeId = item['episodeId'] as String?;
+ final libraryItem = item['libraryItem'] as Map<String, dynamic>?;
+ final media = libraryItem?['media'] as Map<String, dynamic>? ?? {};
+ final duration = (media['duration'] as num?)?.toDouble() ?? 0;
+
+ if (episodeId != null) {
+ if (finished) {
+ await api.updateEpisodeProgress(libraryItemId, episodeId,
+ currentTime: duration, duration: duration, isFinished: true);
+ lib.markFinishedLocally('$libraryItemId-$episodeId', skipAutoAdvance: true);
+ } else {
+ final pd = lib.getProgressData('$libraryItemId-$episodeId');
+ final ct = (pd?['currentTime'] as num?)?.toDouble() ?? 0;
+ await api.updateEpisodeProgress(libraryItemId, episodeId,
+ currentTime: ct, duration: duration, isFinished: false);
+ }
+ } else {
+ if (finished) {
+ await api.markFinished(libraryItemId, duration);
+ lib.markFinishedLocally(libraryItemId, skipAutoAdvance: true);
+ } else {
+ final pd = lib.getProgressData(libraryItemId);
+ final ct = (pd?['currentTime'] as num?)?.toDouble() ?? 0;
+ await api.markNotFinished(libraryItemId, currentTime: ct, duration: duration);
+ }
+ }
+ }
+
+ await lib.refresh();
+ if (mounted) {
+ final count = _selectedKeys.length;
+ setState(() {
+ _isBatchUpdating = false;
+ _selectMode = false;
+ _selectedKeys.clear();
+ });
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text('$count item${count == 1 ? '' : 's'} marked as ${finished ? 'finished' : 'unfinished'}'),
+ behavior: SnackBarBehavior.floating,
+ duration: const Duration(seconds: 2),
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
+ ));
+ }
+ }
+
+ Future<void> _batchRemove(LibraryProvider lib) async {
+ if (_selectedKeys.isEmpty) return;
+ setState(() => _isBatchUpdating = true);
+
+ final playlist = lib.playlists.cast<Map<String, dynamic>>().where(
+ (p) => p['id'] == widget.playlistId,
+ ).firstOrNull;
+ final items = (playlist?['items'] as List<dynamic>?) ?? [];
+
+ for (final key in List<String>.from(_selectedKeys)) {
+ final item = items.cast<Map<String, dynamic>>().where(
+ (i) => _itemKey(i) == key,
+ ).firstOrNull;
+ if (item == null) continue;
+ final libraryItemId = item['libraryItemId'] as String? ?? '';
+ final episodeId = item['episodeId'] as String?;
+ await lib.removeFromPlaylist(widget.playlistId, libraryItemId, episodeId: episodeId);
+ }
+
+ if (mounted) {
+ final count = _selectedKeys.length;
+ setState(() {
+ _isBatchUpdating = false;
+ _selectMode = false;
+ _selectedKeys.clear();
+ });
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text('$count item${count == 1 ? '' : 's'} removed'),
+ behavior: SnackBarBehavior.floating,
+ duration: const Duration(seconds: 2),
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
+ ));
+ }
+ }
Future<void> _removeItem(
LibraryProvider lib,
@@ -166,6 +277,35 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
color: cs.primary, fontWeight: FontWeight.w600,
)),
),
+ ] else if (_selectMode) ...[
+ GestureDetector(
+ onTap: () => setState(() {
+ _selectMode = false;
+ _selectedKeys.clear();
+ }),
+ child: Icon(Icons.close_rounded, size: 20, color: cs.onSurfaceVariant),
+ ),
+ const SizedBox(width: 8),
+ Text('${_selectedKeys.length} selected',
+ style: tt.titleSmall?.copyWith(color: cs.onSurfaceVariant, fontWeight: FontWeight.w600)),
+ const SizedBox(width: 8),
+ GestureDetector(
+ onTap: () {
+ setState(() {
+ if (_selectedKeys.length == items.length) {
+ _selectedKeys.clear();
+ } else {
+ _selectedKeys.clear();
+ for (final i in items) {
+ _selectedKeys.add(_itemKey(i as Map<String, dynamic>));
+ }
+ }
+ });
+ },
+ child: Text('Select All',
+ style: TextStyle(fontSize: 12, color: cs.primary, fontWeight: FontWeight.w500)),
+ ),
+ const Spacer(),
] else ...[
GestureDetector(
onTap: () => _deletePlaylist(context, lib),
@@ -184,7 +324,13 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant),
),
if (items.length > 1) ...[
- const SizedBox(width: 12),
+ const SizedBox(width: 8),
+ GestureDetector(
+ onTap: () => setState(() => _selectMode = true),
+ child: Icon(Icons.checklist_rounded, size: 20,
+ color: cs.onSurfaceVariant.withValues(alpha: 0.6)),
+ ),
+ const SizedBox(width: 8),
GestureDetector(
onTap: () => _startReorder(items),
child: Icon(Icons.tune_rounded, size: 20,
@@ -201,15 +347,53 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
Expanded(
child: _reordering
? _buildReorderList(cs, tt, lib)
- : _buildItemList(cs, tt, lib, items),
+ : _selectMode
+ ? _buildSelectList(cs, tt, lib, items)
+ : _buildItemList(cs, tt, lib, items),
),
+ // Batch action bar
+ if (_selectMode && _selectedKeys.isNotEmpty)
+ Container(
+ padding: EdgeInsets.fromLTRB(16, 8, 16, 8 + MediaQuery.of(context).viewPadding.bottom),
+ decoration: BoxDecoration(
+ color: cs.surfaceContainer,
+ border: Border(top: BorderSide(color: cs.outlineVariant.withValues(alpha: 0.3))),
+ ),
+ child: _isBatchUpdating
+ ? Center(child: SizedBox(width: 20, height: 20,
+ child: CircularProgressIndicator(strokeWidth: 2, color: cs.primary)))
+ : Row(children: [
+ Expanded(child: FilledButton.tonalIcon(
+ onPressed: () => _batchMarkFinished(true, lib),
+ icon: const Icon(Icons.check_circle_rounded, size: 18),
+ label: const Text('Finished'),
+ style: FilledButton.styleFrom(visualDensity: VisualDensity.compact),
+ )),
+ const SizedBox(width: 8),
+ Expanded(child: OutlinedButton.icon(
+ onPressed: () => _batchMarkFinished(false, lib),
+ icon: const Icon(Icons.radio_button_unchecked_rounded, size: 18),
+ label: const Text('Unfinished'),
+ style: OutlinedButton.styleFrom(visualDensity: VisualDensity.compact),
+ )),
+ const SizedBox(width: 8),
+ IconButton(
+ onPressed: () => _batchRemove(lib),
+ icon: Icon(Icons.playlist_remove_rounded, color: cs.error),
+ tooltip: 'Remove from playlist',
+ style: IconButton.styleFrom(
+ backgroundColor: cs.error.withValues(alpha: 0.1),
+ ),
+ ),
+ ]),
+ ),
]);
}
Widget _buildReorderList(ColorScheme cs, TextTheme tt, LibraryProvider lib) {
final items = _reorderItems!;
return ReorderableListView.builder(
- padding: const EdgeInsets.symmetric(vertical: 8),
+ padding: EdgeInsets.only(top: 8, bottom: 8 + MediaQuery.of(context).viewPadding.bottom),
onReorderStart: (_) => HapticFeedback.mediumImpact(),
onReorder: (oldIndex, newIndex) {
setState(() {
@@ -286,10 +470,89 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
);
}
+ Widget _buildSelectList(ColorScheme cs, TextTheme tt, LibraryProvider lib, List<dynamic> items) {
+ return ListView.builder(
+ controller: widget.scrollController,
+ padding: EdgeInsets.only(bottom: (_selectedKeys.isNotEmpty ? 64.0 : 32.0) + MediaQuery.of(context).viewPadding.bottom),
+ itemCount: items.length,
+ itemBuilder: (context, index) {
+ final item = items[index] as Map<String, dynamic>;
+ final libraryItemId = item['libraryItemId'] as String? ?? '';
+ final episodeId = item['episodeId'] as String?;
+ final libraryItem = item['libraryItem'] as Map<String, dynamic>?;
+ if (libraryItem == null) return const SizedBox.shrink();
+
+ final media = libraryItem['media'] as Map<String, dynamic>? ?? {};
+ final metadata = media['metadata'] as Map<String, dynamic>? ?? {};
+ final title = metadata['title'] as String? ?? 'Unknown';
+ final author = metadata['authorName'] as String? ?? '';
+ final coverUrl = lib.getCoverUrl(libraryItemId);
+ final key = _itemKey(item);
+ final selected = _selectedKeys.contains(key);
+
+ String? episodeTitle;
+ if (episodeId != null) {
+ final episodes = media['episodes'] as List<dynamic>? ?? [];
+ final ep = episodes.cast<Map<String, dynamic>>().where(
+ (e) => e['id'] == episodeId,
+ ).firstOrNull;
+ episodeTitle = ep?['title'] as String?;
+ }
+
+ return InkWell(
+ onTap: () => setState(() {
+ if (selected) { _selectedKeys.remove(key); } else { _selectedKeys.add(key); }
+ }),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(12, 6, 12, 6),
+ child: Row(children: [
+ Checkbox(
+ value: selected,
+ onChanged: (v) => setState(() {
+ if (v == true) { _selectedKeys.add(key); } else { _selectedKeys.remove(key); }
+ }),
+ visualDensity: VisualDensity.compact,
+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ ),
+ const SizedBox(width: 8),
+ SizedBox(
+ width: 40, height: 40,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(6),
+ child: coverUrl != null
+ ? (coverUrl.startsWith('/')
+ ? Image.file(File(coverUrl), fit: BoxFit.cover,
+ errorBuilder: (_, __, ___) => _placeholder(cs))
+ : Image.network(coverUrl, fit: BoxFit.cover,
+ headers: lib.mediaHeaders,
+ errorBuilder: (_, __, ___) => _placeholder(cs)))
+ : _placeholder(cs),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(episodeTitle ?? title, maxLines: 1, overflow: TextOverflow.ellipsis,
+ style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: cs.onSurface)),
+ Text(episodeTitle != null ? title : author, maxLines: 1, overflow: TextOverflow.ellipsis,
+ style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant)),
+ ],
+ )),
+ ]),
+ ),
+ );
+ },
+ );
+ }
+
Widget _buildItemList(ColorScheme cs, TextTheme tt, LibraryProvider lib, List<dynamic> items) {
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final doneColor = isDark ? Colors.greenAccent[400]! : Colors.green.shade700;
+
return ListView.builder(
controller: widget.scrollController,
- padding: const EdgeInsets.only(bottom: 40),
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4).copyWith(bottom: 40),
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index] as Map<String, dynamic>;
@@ -304,6 +567,10 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
final title = metadata['title'] as String? ?? 'Unknown';
final author = metadata['authorName'] as String? ?? '';
final coverUrl = lib.getCoverUrl(libraryItemId);
+ final progressKey = episodeId != null ? '$libraryItemId-$episodeId' : libraryItemId;
+ final progress = lib.getProgress(progressKey);
+ final isFinished = lib.getProgressData(progressKey)?['isFinished'] == true;
+ final isDownloaded = DownloadService().isDownloaded(libraryItemId);
String? episodeTitle;
if (episodeId != null) {
@@ -324,47 +591,112 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
color: cs.error.withValues(alpha: 0.1),
child: Icon(Icons.delete_rounded, color: cs.error),
),
- child: ListTile(
- contentPadding: const EdgeInsets.symmetric(horizontal: 20),
- leading: SizedBox(
- width: 44, height: 44,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(6),
- child: coverUrl != null
- ? (coverUrl.startsWith('/')
- ? Image.file(File(coverUrl), fit: BoxFit.cover,
- errorBuilder: (_, __, ___) => _placeholder(cs))
- : Image.network(coverUrl, fit: BoxFit.cover,
- headers: lib.mediaHeaders,
- errorBuilder: (_, __, ___) => _placeholder(cs)))
- : _placeholder(cs),
- ),
- ),
- title: Text(
- episodeTitle ?? title,
- maxLines: 1, overflow: TextOverflow.ellipsis,
- style: tt.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500, color: cs.onSurface,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Card(
+ elevation: 0,
+ color: cs.surfaceContainerHigh,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
+ clipBehavior: Clip.antiAlias,
+ child: InkWell(
+ onTap: () {
+ if (episodeId != null) {
+ final episodes = media['episodes'] as List<dynamic>? ?? [];
+ final ep = episodes.cast<Map<String, dynamic>>().where(
+ (e) => e['id'] == episodeId,
+ ).firstOrNull;
+ if (ep != null) {
+ EpisodeDetailSheet.show(context, libraryItem, ep);
+ }
+ } else {
+ showBookDetailSheet(context, libraryItemId);
+ }
+ },
+ borderRadius: BorderRadius.circular(14),
+ child: SizedBox(
+ height: 112,
+ child: Row(children: [
+ AspectRatio(
+ aspectRatio: 1,
+ child: Stack(children: [
+ Positioned.fill(
+ child: coverUrl != null
+ ? (coverUrl.startsWith('/')
+ ? Image.file(File(coverUrl), fit: BoxFit.cover,
+ errorBuilder: (_, __, ___) => _placeholder(cs))
+ : CachedNetworkImage(
+ imageUrl: coverUrl, fit: BoxFit.cover,
+ httpHeaders: lib.mediaHeaders,
+ placeholder: (_, __) => _placeholder(cs),
+ errorWidget: (_, __, ___) => _placeholder(cs),
+ ))
+ : _placeholder(cs),
+ ),
+ if (progress > 0 && !isFinished)
+ Positioned(
+ left: 0, right: 0, bottom: 0,
+ child: LinearProgressIndicator(
+ value: progress.clamp(0.0, 1.0),
+ minHeight: 3,
+ backgroundColor: Colors.black38,
+ valueColor: AlwaysStoppedAnimation(cs.primary),
+ ),
+ ),
+ if (isFinished || isDownloaded)
+ Positioned(
+ left: 0, right: 0, bottom: 0,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.bottomCenter,
+ end: Alignment.topCenter,
+ colors: [
+ Colors.black.withValues(alpha: 0.85),
+ Colors.black.withValues(alpha: 0.0),
+ ],
+ ),
+ ),
+ child: Column(mainAxisSize: MainAxisSize.min, children: [
+ if (isFinished)
+ Row(mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [
+ Icon(Icons.check_circle_rounded, size: 10, color: doneColor),
+ const SizedBox(width: 3),
+ Text('Done', style: TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: doneColor)),
+ ]),
+ if (isDownloaded)
+ Row(mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [
+ Icon(Icons.download_done_rounded, size: 10, color: cs.primary),
+ const SizedBox(width: 3),
+ Text('Saved', style: TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: cs.primary)),
+ ]),
+ ]),
+ ),
+ ),
+ ]),
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(episodeTitle ?? title,
+ maxLines: 2, overflow: TextOverflow.ellipsis,
+ style: tt.bodyMedium?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface)),
+ const SizedBox(height: 4),
+ Text(episodeTitle != null ? title : author,
+ maxLines: 1, overflow: TextOverflow.ellipsis,
+ style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant)),
+ ],
+ ),
+ ),
+ ),
+ ]),
+ ),
),
),
- subtitle: Text(
- episodeTitle != null ? title : author,
- maxLines: 1, overflow: TextOverflow.ellipsis,
- style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant),
- ),
- onTap: () {
- if (episodeId != null) {
- final episodes = media['episodes'] as List<dynamic>? ?? [];
- final ep = episodes.cast<Map<String, dynamic>>().where(
- (e) => e['id'] == episodeId,
- ).firstOrNull;
- if (ep != null) {
- EpisodeDetailSheet.show(context, libraryItem, ep);
- }
- } else {
- showBookDetailSheet(context, libraryItemId);
- }
- },
),
);
},