A cross platform Audiobookshelf client for Android and iOS
Dart
Swipe-down pops current sheet only, stack capped at 3
Nathan Poulsonac8cc44b0582
diff --git a/lib/widgets/episode_detail_sheet.dart b/lib/widgets/episode_detail_sheet.dartindex c5e5f1ee..7e5f4018 100644--- a/lib/widgets/episode_detail_sheet.dart+++ b/lib/widgets/episode_detail_sheet.dart@@ -460,9 +460,7 @@ class _EpisodeDetailSheetState extends State<EpisodeDetailSheet> {const SizedBox(height: 16),GestureDetector(onTap: () {- final nav = Navigator.of(context);- nav.pop();- EpisodeListSheet.show(nav.context, widget.podcastItem);+ EpisodeListSheet.show(context, widget.podcastItem);},child: Container(padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),diff --git a/lib/widgets/episode_row.dart b/lib/widgets/episode_row.dartindex 9ad24981..6de0ff49 100644--- a/lib/widgets/episode_row.dart+++ b/lib/widgets/episode_row.dart@@ -81,10 +81,7 @@ class _EpisodeRowState extends State<EpisodeRow> {return InkWell(onTap: () {- // Close episode list before opening detail to prevent infinite stacking- final nav = Navigator.of(context);- nav.pop();- EpisodeDetailSheet.show(nav.context, widget.podcastItem, ep);+ EpisodeDetailSheet.show(context, widget.podcastItem, ep);},child: Padding(padding: const EdgeInsets.fromLTRB(20, 10, 12, 10),diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dartindex 1011f8c7..9cee1809 100644--- a/lib/widgets/library_search_results.dart+++ b/lib/widgets/library_search_results.dart@@ -13,7 +13,6 @@ class BookResultTile extends StatelessWidget {final Map<String, dynamic> item;final String? serverUrl;final String? token;- final bool popOnTap;final String? subtitle;final String? sequenceBadge;@@ -22,7 +21,6 @@ class BookResultTile extends StatelessWidget {required this.item,required this.serverUrl,required this.token,- this.popOnTap = false,this.subtitle,this.sequenceBadge,});@@ -64,14 +62,11 @@ class BookResultTile extends StatelessWidget {onTap: () {FocusManager.instance.primaryFocus?.unfocus();if (itemId != null) {- final nav = Navigator.of(context);- if (popOnTap) nav.pop();- final ctx = popOnTap ? nav.context : context;- final lib = ctx.read<LibraryProvider>();+ final lib = context.read<LibraryProvider>();if (lib.isPodcastLibrary) {- EpisodeListSheet.show(ctx, item);+ EpisodeListSheet.show(context, item);} else {- showBookDetailSheet(ctx, itemId);+ showBookDetailSheet(context, itemId);}}},diff --git a/lib/widgets/stackable_sheet.dart b/lib/widgets/stackable_sheet.dartindex 75c7ea81..50cd80ad 100644--- a/lib/widgets/stackable_sheet.dart+++ b/lib/widgets/stackable_sheet.dart@@ -1,9 +1,13 @@import 'package:flutter/material.dart';+const int maxSheetDepth = 3;+final List<Route<dynamic>> _activeSheetRoutes = [];+/// 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.+/// Drag to minimum size closes the current sheet only (revealing any sheet below).+/// Back button / barrier tap also closes only the current sheet.+/// Stack is capped at [maxSheetDepth] - opening beyond that evicts the oldest sheet.Future<T?> showStackableSheet<T>({required BuildContext context,required Widget Function(BuildContext, ScrollController) builder,@@ -15,10 +19,22 @@ Future<T?> showStackableSheet<T>({bool showHandle = false,}) {FocusManager.instance.primaryFocus?.unfocus();++ // Enforce stack cap: evict the oldest sheet before opening a new one+ if (_activeSheetRoutes.length >= maxSheetDepth) {+ final oldest = _activeSheetRoutes.first;+ try {+ Navigator.of(context).removeRoute(oldest);+ } catch (_) {+ // Route may already be disposed (e.g. rapid navigation)+ _activeSheetRoutes.remove(oldest);+ }+ }+return showModalBottomSheet<T>(context: context,isScrollControlled: true,- enableDrag: false,+ enableDrag: true,useSafeArea: useSafeArea,backgroundColor: backgroundColor ?? (showHandle ? null : Colors.transparent),builder: (_) => _StackableSheet(@@ -53,15 +69,23 @@ class _StackableSheet extends StatefulWidget {class _StackableSheetState extends State<_StackableSheet> {final _controller = DraggableScrollableController();bool _dismissed = false;+ Route<dynamic>? _ownRoute;@overridevoid initState() {super.initState();_controller.addListener(_onSizeChanged);+ WidgetsBinding.instance.addPostFrameCallback((_) {+ _ownRoute = ModalRoute.of(context);+ if (_ownRoute != null) {+ _activeSheetRoutes.add(_ownRoute!);+ }+ });}@overridevoid dispose() {+ if (_ownRoute != null) _activeSheetRoutes.remove(_ownRoute!);_controller.removeListener(_onSizeChanged);_controller.dispose();super.dispose();@@ -70,7 +94,7 @@ class _StackableSheetState extends State<_StackableSheet> {void _onSizeChanged() {if (!_dismissed && _controller.size <= widget.minChildSize) {_dismissed = true;- Navigator.of(context).popUntil((route) => route is! PopupRoute);+ Navigator.of(context).pop();}}