Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: fullscreen bottom sheet in dialog helper

Predidit56d35199e1c2
diff --git a/lib/bean/dialog/dialog_helper.dart b/lib/bean/dialog/dialog_helper.dart
index dcfb2cd5..1842c49e 100644
--- a/lib/bean/dialog/dialog_helper.dart
+++ b/lib/bean/dialog/dialog_helper.dart
@@ -126,6 +126,58 @@ class KazumiDialog {
}
}
+ static Future<T?> showBottomSheet<T>({
+ BuildContext? context,
+ required WidgetBuilder builder,
+ Color? backgroundColor,
+ double? elevation,
+ ShapeBorder? shape,
+ Clip? clipBehavior,
+ BoxConstraints? constraints,
+ Color? barrierColor,
+ bool isScrollControlled = false,
+ bool useRootNavigator = true,
+ bool isDismissible = true,
+ bool enableDrag = true,
+ RouteSettings? routeSettings,
+ AnimationController? transitionAnimationController,
+ Offset? anchorPoint,
+ bool useSafeArea = false,
+ }) async {
+ // Use provided context first, then root context, then fallback to current context
+ final ctx = context ?? observer.rootContext ?? observer.currentContext;
+ if (ctx != null && ctx.mounted) {
+ try {
+ final result = await showModalBottomSheet<T>(
+ context: ctx,
+ builder: builder,
+ backgroundColor: backgroundColor,
+ elevation: elevation,
+ shape: shape,
+ clipBehavior: clipBehavior,
+ constraints: constraints,
+ barrierColor: barrierColor,
+ isScrollControlled: isScrollControlled,
+ useRootNavigator: useRootNavigator,
+ isDismissible: isDismissible,
+ enableDrag: enableDrag,
+ routeSettings: routeSettings ?? const RouteSettings(name: 'KazumiBottomSheet'),
+ transitionAnimationController: transitionAnimationController,
+ anchorPoint: anchorPoint,
+ useSafeArea: useSafeArea,
+ );
+ return result;
+ } catch (e) {
+ debugPrint('Kazumi Dialog Error: Failed to show bottom sheet: $e');
+ return null;
+ }
+ } else {
+ debugPrint(
+ 'Kazumi Dialog Error: No context available to show the bottom sheet');
+ return null;
+ }
+ }
+
static void dismiss() {
if (observer.hasKazumiDialog && observer.kazumiDialogContext != null) {
try {
@@ -150,10 +202,16 @@ class KazumiDialogObserver extends NavigatorObserver {
/// The most recent context from any route containing a Scaffold
BuildContext? _scaffoldContext;
+ /// The root context of the app (for bottom sheets to cover the entire app)
+ BuildContext? _rootContext;
+
BuildContext? get currentContext => _currentContext;
BuildContext? get scaffoldContext => _scaffoldContext ?? _currentContext;
+ /// Get the root context for bottom sheets, fallback to scaffold context, then current context
+ BuildContext? get rootContext => _rootContext ?? _scaffoldContext ?? _currentContext;
+
bool get hasKazumiDialog => _kazumiDialogRoutes.isNotEmpty;
BuildContext? get kazumiDialogContext => _kazumiDialogRoutes.isNotEmpty
@@ -219,6 +277,9 @@ class KazumiDialogObserver extends NavigatorObserver {
_currentContext = context;
if (_hasScaffold(context)) {
_scaffoldContext = context;
+ // Always update root context with scaffold contexts to ensure we have the most recent one
+ // This helps ensure bottom sheets appear at the app level
+ _rootContext = context;
}
}
@@ -227,7 +288,8 @@ class KazumiDialogObserver extends NavigatorObserver {
}
bool _isKazumiDialogRoute(Route<dynamic> route) {
- return route.settings.name == 'KazumiDialog';
+ return route.settings.name == 'KazumiDialog' ||
+ route.settings.name == 'KazumiBottomSheet';
}
void _removeCurrentSnackBar(Route<dynamic>? route) {
diff --git a/lib/pages/timeline/timeline_page.dart b/lib/pages/timeline/timeline_page.dart
index 8e3a242b..b28b822a 100644
--- a/lib/pages/timeline/timeline_page.dart
+++ b/lib/pages/timeline/timeline_page.dart
@@ -106,8 +106,8 @@ class _TimelinePageState extends State<TimelinePage>
}
}
- showModalBottomSheet(
- context: context,
+ KazumiDialog.showBottomSheet(
+ // context: context,
backgroundColor: Theme.of(context).colorScheme.surface,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(28)),