Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Stackable sheet navigation - back goes to previous sheet, drag down closes all

Nathan Poulson40818b5753d3
diff --git a/lib/widgets/author_books_sheet.dart b/lib/widgets/author_books_sheet.dart
index e747cc7b..f297ebd8 100644
--- a/lib/widgets/author_books_sheet.dart
+++ b/lib/widgets/author_books_sheet.dart
@@ -7,6 +7,7 @@ import '../services/audio_player_service.dart';
import 'library_grid_tiles.dart';
import 'library_search_results.dart';
import 'series_books_sheet.dart';
+import 'stackable_sheet.dart';
enum _AuthorLayout { list, grid }
@@ -15,26 +16,18 @@ void showAuthorDetailSheet(BuildContext context, {
required String authorId,
required String authorName,
}) {
- FocusManager.instance.primaryFocus?.unfocus();
final auth = context.read<AuthProvider>();
final lib = context.read<LibraryProvider>();
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
- showDragHandle: true,
- builder: (_) => DraggableScrollableSheet(
- initialChildSize: 0.7,
- minChildSize: 0.05, snap: true,
- maxChildSize: 0.9,
- expand: false,
- builder: (ctx, scrollController) => AuthorBooksSheet(
- libraryId: lib.selectedLibraryId ?? '',
- authorId: authorId,
- authorName: authorName,
- serverUrl: auth.serverUrl,
- token: auth.token,
- scrollController: scrollController,
- ),
+ showHandle: true,
+ builder: (ctx, scrollController) => AuthorBooksSheet(
+ libraryId: lib.selectedLibraryId ?? '',
+ authorId: authorId,
+ authorName: authorName,
+ serverUrl: auth.serverUrl,
+ token: auth.token,
+ scrollController: scrollController,
),
);
}
@@ -525,7 +518,6 @@ class _AuthorBooksSheetState extends State<AuthorBooksSheet> {
item: book,
serverUrl: widget.serverUrl,
token: widget.token,
- popOnTap: true,
subtitle: _sequenceFor(book, sectionLabel),
sequenceBadge: _sequenceFor(book, sectionLabel)?.replaceFirst('#', ''),
),
diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dart
index 99e2a84d..8d64e5cc 100644
--- a/lib/widgets/book_detail_sheet.dart
+++ b/lib/widgets/book_detail_sheet.dart
@@ -31,17 +31,17 @@ import 'playlist_picker_sheet.dart';
import 'collection_picker_sheet.dart';
import 'absorb_wave_icon.dart';
import 'edit_metadata_sheet.dart';
+import 'stackable_sheet.dart';
// ─── BOOK DETAIL BOTTOM SHEET ───────────────────────────────
void showBookDetailSheet(BuildContext context, String itemId) {
- showModalBottomSheet(
- context: context, isScrollControlled: true, useSafeArea: true,
- backgroundColor: Colors.transparent,
- builder: (ctx) => DraggableScrollableSheet(
- expand: false, initialChildSize: 0.85, minChildSize: 0.05, snap: true, maxChildSize: 0.95,
- builder: (ctx, sc) => _BookDetailSheetContent(itemId: itemId, scrollController: sc),
- ),
+ showStackableSheet(
+ context: context,
+ useSafeArea: true,
+ initialChildSize: 0.85,
+ maxChildSize: 0.95,
+ builder: (ctx, sc) => _BookDetailSheetContent(itemId: itemId, scrollController: sc),
);
}
@@ -815,9 +815,7 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
final id = a['id'] as String? ?? '';
final name = a['name'] as String? ?? '';
if (id.isEmpty || name.isEmpty) return;
- final nav = Navigator.of(context);
- nav.pop();
- showAuthorDetailSheet(nav.context, authorId: id, authorName: name);
+ showAuthorDetailSheet(context, authorId: id, authorName: name);
},
child: Text(
(visible[i] as Map<String, dynamic>?)?['name'] as String? ?? '',
@@ -842,11 +840,8 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
if (seriesId == null) return;
final auth = context.read<AuthProvider>();
final itemLibraryId = _item?['libraryId'] as String?;
- // Close current sheet before opening series to prevent infinite stacking
- final nav = Navigator.of(context);
- nav.pop();
showSeriesBooksSheet(
- nav.context,
+ context,
seriesName: seriesName,
seriesId: seriesId,
serverUrl: auth.serverUrl,
diff --git a/lib/widgets/collection_detail_sheet.dart b/lib/widgets/collection_detail_sheet.dart
index cdcd6071..7491eef0 100644
--- a/lib/widgets/collection_detail_sheet.dart
+++ b/lib/widgets/collection_detail_sheet.dart
@@ -7,6 +7,7 @@ import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
import '../services/download_service.dart';
import 'book_detail_sheet.dart';
+import 'stackable_sheet.dart';
class CollectionDetailSheet extends StatefulWidget {
final String collectionId;
@@ -19,38 +20,15 @@ class CollectionDetailSheet extends StatefulWidget {
});
static void show(BuildContext context, String collectionId) {
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
useSafeArea: true,
- backgroundColor: Colors.transparent,
- builder: (context) {
- return GestureDetector(
- onTap: () => Navigator.pop(context),
- behavior: HitTestBehavior.opaque,
- child: DraggableScrollableSheet(
- initialChildSize: 0.7,
- minChildSize: 0.4,
- maxChildSize: 0.95,
- builder: (context, scrollController) {
- return GestureDetector(
- onTap: () {},
- child: Container(
- decoration: BoxDecoration(
- color: Theme.of(context).bottomSheetTheme.backgroundColor ??
- Theme.of(context).colorScheme.surface,
- borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
- ),
- child: CollectionDetailSheet(
- collectionId: collectionId,
- scrollController: scrollController,
- ),
- ),
- );
- },
- ),
- );
- },
+ showHandle: true,
+ maxChildSize: 0.95,
+ builder: (context, scrollController) => CollectionDetailSheet(
+ collectionId: collectionId,
+ scrollController: scrollController,
+ ),
);
}
@@ -137,16 +115,7 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
final books = (collection['books'] as List<dynamic>?) ?? [];
return Column(children: [
- // Grab handle + header
- const SizedBox(height: 8),
- Center(child: Container(
- width: 40, height: 4,
- decoration: BoxDecoration(
- color: cs.onSurface.withValues(alpha: 0.24),
- borderRadius: BorderRadius.circular(2),
- ),
- )),
- const SizedBox(height: 16),
+ const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(children: [
diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dart
index a8dfd829..bee192cd 100644
--- a/lib/widgets/episode_list_sheet.dart
+++ b/lib/widgets/episode_list_sheet.dart
@@ -12,6 +12,7 @@ import '../providers/auth_provider.dart';
import 'card_buttons.dart';
import 'html_description.dart';
import 'playlist_picker_sheet.dart';
+import 'stackable_sheet.dart';
/// Bottom sheet that shows a podcast's episode list.
/// Mirrors the UX of [BookDetailSheet] but adapted for podcast shows.
@@ -29,20 +30,14 @@ class EpisodeListSheet extends StatefulWidget {
/// Show the episode list as a modal bottom sheet.
static void show(BuildContext context, Map<String, dynamic> podcastItem) {
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
useSafeArea: true,
- backgroundColor: Colors.transparent,
- builder: (_) => DraggableScrollableSheet(
- initialChildSize: 0.85,
- minChildSize: 0.05, snap: true,
- maxChildSize: 0.95,
- expand: false,
- builder: (_, scrollController) => EpisodeListSheet._(
- podcastItem: podcastItem,
- scrollController: scrollController,
- ),
+ initialChildSize: 0.85,
+ maxChildSize: 0.95,
+ builder: (_, scrollController) => EpisodeListSheet._(
+ podcastItem: podcastItem,
+ scrollController: scrollController,
),
);
}
@@ -860,21 +855,15 @@ class EpisodeDetailSheet extends StatefulWidget {
}) : super(key: null);
static void show(BuildContext context, Map<String, dynamic> podcastItem, Map<String, dynamic> episode) {
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
useSafeArea: true,
- backgroundColor: Colors.transparent,
- builder: (_) => DraggableScrollableSheet(
- initialChildSize: 0.75,
- minChildSize: 0.05, snap: true,
- maxChildSize: 0.95,
- expand: false,
- builder: (_, scrollController) => EpisodeDetailSheet._(
- podcastItem: podcastItem,
- episode: episode,
- scrollController: scrollController,
- ),
+ initialChildSize: 0.75,
+ maxChildSize: 0.95,
+ builder: (_, scrollController) => EpisodeDetailSheet._(
+ podcastItem: podcastItem,
+ episode: episode,
+ scrollController: scrollController,
),
);
}
diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dart
index 4ff606a6..00098595 100644
--- a/lib/widgets/library_search_results.dart
+++ b/lib/widgets/library_search_results.dart
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:provider/provider.dart';
-import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
import '../services/download_service.dart';
import 'author_books_sheet.dart';
@@ -498,30 +497,6 @@ class AuthorResultTile extends StatelessWidget {
void _showAuthorBooks(
BuildContext context, String authorId, String authorName) {
- FocusManager.instance.primaryFocus?.unfocus();
- final auth = context.read<AuthProvider>();
- final lib = context.read<LibraryProvider>();
- final api = auth.apiService;
- if (api == null || lib.selectedLibraryId == null) return;
-
- showModalBottomSheet(
- context: context,
- isScrollControlled: true,
- showDragHandle: true,
- builder: (_) => DraggableScrollableSheet(
- initialChildSize: 0.7,
- minChildSize: 0.05, snap: true,
- maxChildSize: 0.9,
- expand: false,
- builder: (ctx, scrollController) => AuthorBooksSheet(
- libraryId: lib.selectedLibraryId!,
- authorId: authorId,
- authorName: authorName,
- serverUrl: auth.serverUrl,
- token: auth.token,
- scrollController: scrollController,
- ),
- ),
- );
+ showAuthorDetailSheet(context, authorId: authorId, authorName: authorName);
}
}
diff --git a/lib/widgets/playlist_detail_sheet.dart b/lib/widgets/playlist_detail_sheet.dart
index e692829c..caca9682 100644
--- a/lib/widgets/playlist_detail_sheet.dart
+++ b/lib/widgets/playlist_detail_sheet.dart
@@ -8,6 +8,7 @@ import '../providers/library_provider.dart';
import '../services/download_service.dart';
import 'book_detail_sheet.dart';
import 'episode_list_sheet.dart';
+import 'stackable_sheet.dart';
class PlaylistDetailSheet extends StatefulWidget {
final String playlistId;
@@ -20,38 +21,15 @@ class PlaylistDetailSheet extends StatefulWidget {
});
static void show(BuildContext context, String playlistId) {
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
useSafeArea: true,
- backgroundColor: Colors.transparent,
- builder: (context) {
- return GestureDetector(
- onTap: () => Navigator.pop(context),
- behavior: HitTestBehavior.opaque,
- child: DraggableScrollableSheet(
- initialChildSize: 0.7,
- minChildSize: 0.4,
- maxChildSize: 0.95,
- builder: (context, scrollController) {
- return GestureDetector(
- onTap: () {},
- child: Container(
- decoration: BoxDecoration(
- color: Theme.of(context).bottomSheetTheme.backgroundColor ??
- Theme.of(context).colorScheme.surface,
- borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
- ),
- child: PlaylistDetailSheet(
- playlistId: playlistId,
- scrollController: scrollController,
- ),
- ),
- );
- },
- ),
- );
- },
+ showHandle: true,
+ maxChildSize: 0.95,
+ builder: (context, scrollController) => PlaylistDetailSheet(
+ playlistId: playlistId,
+ scrollController: scrollController,
+ ),
);
}
@@ -246,16 +224,7 @@ class _PlaylistDetailSheetState extends State<PlaylistDetailSheet> {
final items = (playlist['items'] as List<dynamic>?) ?? [];
return Column(children: [
- // Grab handle + header
- const SizedBox(height: 8),
- Center(child: Container(
- width: 40, height: 4,
- decoration: BoxDecoration(
- color: cs.onSurface.withValues(alpha: 0.24),
- borderRadius: BorderRadius.circular(2),
- ),
- )),
- const SizedBox(height: 16),
+ const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(children: [
diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dart
index 6068c1cf..32421a8f 100644
--- a/lib/widgets/series_books_sheet.dart
+++ b/lib/widgets/series_books_sheet.dart
@@ -8,6 +8,7 @@ import '../services/download_service.dart';
import 'book_detail_sheet.dart';
import 'library_grid_tiles.dart';
import 'episode_list_sheet.dart';
+import 'stackable_sheet.dart';
/// Show a bottom sheet with all books in a series, sorted by sequence.
/// Can be called from any screen.
@@ -19,25 +20,17 @@ void showSeriesBooksSheet(BuildContext context, {
String? token,
String? libraryId,
}) {
- FocusManager.instance.primaryFocus?.unfocus();
- showModalBottomSheet(
+ showStackableSheet(
context: context,
- isScrollControlled: true,
- showDragHandle: true,
- builder: (_) => DraggableScrollableSheet(
- initialChildSize: 0.7,
- minChildSize: 0.05, snap: true,
- maxChildSize: 0.9,
- expand: false,
- builder: (ctx, scrollController) => SeriesBooksSheet(
- seriesName: seriesName,
- seriesId: seriesId,
- books: books,
- serverUrl: serverUrl,
- token: token,
- libraryId: libraryId,
- scrollController: scrollController,
- ),
+ showHandle: true,
+ builder: (ctx, scrollController) => SeriesBooksSheet(
+ seriesName: seriesName,
+ seriesId: seriesId,
+ books: books,
+ serverUrl: serverUrl,
+ token: token,
+ libraryId: libraryId,
+ scrollController: scrollController,
),
);
}
@@ -720,13 +713,10 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
child: InkWell(
onTap: () {
if (bookId.isNotEmpty) {
- // Close series sheet before opening book to prevent infinite stacking
- final nav = Navigator.of(context);
- nav.pop();
if (lib.isPodcastLibrary) {
- EpisodeListSheet.show(nav.context, book);
+ EpisodeListSheet.show(context, book);
} else {
- showBookDetailSheet(nav.context, bookId);
+ showBookDetailSheet(context, bookId);
}
}
},
diff --git a/lib/widgets/stackable_sheet.dart b/lib/widgets/stackable_sheet.dart
new file mode 100644
index 00000000..75c7ea81
--- /dev/null
+++ b/lib/widgets/stackable_sheet.dart
@@ -0,0 +1,121 @@
+import 'package:flutter/material.dart';
+
+/// Shows a modal bottom sheet that supports stacking.
+///
+/// Drag to minimum size closes ALL stacked sheets (popUntil non-popup route).
+/// Back button / barrier tap closes only the current sheet.
+Future<T?> showStackableSheet<T>({
+ required BuildContext context,
+ required Widget Function(BuildContext, ScrollController) builder,
+ double initialChildSize = 0.7,
+ double minChildSize = 0.05,
+ double maxChildSize = 0.9,
+ Color? backgroundColor,
+ bool useSafeArea = false,
+ bool showHandle = false,
+}) {
+ FocusManager.instance.primaryFocus?.unfocus();
+ return showModalBottomSheet<T>(
+ context: context,
+ isScrollControlled: true,
+ enableDrag: false,
+ useSafeArea: useSafeArea,
+ backgroundColor: backgroundColor ?? (showHandle ? null : Colors.transparent),
+ builder: (_) => _StackableSheet(
+ initialChildSize: initialChildSize,
+ minChildSize: minChildSize,
+ maxChildSize: maxChildSize,
+ showHandle: showHandle,
+ builder: builder,
+ ),
+ );
+}
+
+class _StackableSheet extends StatefulWidget {
+ final double initialChildSize;
+ final double minChildSize;
+ final double maxChildSize;
+ final bool showHandle;
+ final Widget Function(BuildContext, ScrollController) builder;
+
+ const _StackableSheet({
+ required this.initialChildSize,
+ required this.minChildSize,
+ required this.maxChildSize,
+ required this.showHandle,
+ required this.builder,
+ });
+
+ @override
+ State<_StackableSheet> createState() => _StackableSheetState();
+}
+
+class _StackableSheetState extends State<_StackableSheet> {
+ final _controller = DraggableScrollableController();
+ bool _dismissed = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _controller.addListener(_onSizeChanged);
+ }
+
+ @override
+ void dispose() {
+ _controller.removeListener(_onSizeChanged);
+ _controller.dispose();
+ super.dispose();
+ }
+
+ void _onSizeChanged() {
+ if (!_dismissed && _controller.size <= widget.minChildSize) {
+ _dismissed = true;
+ Navigator.of(context).popUntil((route) => route is! PopupRoute);
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return DraggableScrollableSheet(
+ controller: _controller,
+ initialChildSize: widget.initialChildSize,
+ minChildSize: widget.minChildSize,
+ maxChildSize: widget.maxChildSize,
+ snap: true,
+ expand: false,
+ builder: (ctx, scrollController) {
+ final content = widget.builder(ctx, scrollController);
+ if (widget.showHandle) {
+ final cs = Theme.of(context).colorScheme;
+ return Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ color: Theme.of(context).bottomSheetTheme.backgroundColor ??
+ cs.surface,
+ borderRadius:
+ const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ children: [
+ const SizedBox(height: 12),
+ Center(
+ child: Container(
+ width: 32,
+ height: 4,
+ decoration: BoxDecoration(
+ color: cs.onSurfaceVariant.withValues(alpha: 0.4),
+ borderRadius: BorderRadius.circular(2),
+ ),
+ ),
+ ),
+ const SizedBox(height: 12),
+ Expanded(child: content),
+ ],
+ ),
+ );
+ }
+ return content;
+ },
+ );
+ }
+}