From 8fc319d9808e4cc1f8565ea9854570ab088de85b Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Mon, 7 Apr 2025 14:53:05 +0600 Subject: [PATCH] fix(mobile): dialogs in bottom sheet are not opening --- android/app/src/debug/AndroidManifest.xml | 13 ++++++ .../adaptive/adaptive_pop_sheet_list.dart | 17 ++++---- .../presentation_actions.dart | 42 ++++++++++++------- .../track_presentation/presentation_top.dart | 6 +-- lib/components/track_tile/track_options.dart | 27 ++++-------- lib/modules/player/player.dart | 2 +- lib/modules/player/player_actions.dart | 8 ++-- 7 files changed, 64 insertions(+), 51 deletions(-) diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index a32d12af..400c91e8 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -3,4 +3,17 @@ to allow setting breakpoints, to provide hot reload, etc. --> + + + + \ No newline at end of file diff --git a/lib/components/adaptive/adaptive_pop_sheet_list.dart b/lib/components/adaptive/adaptive_pop_sheet_list.dart index 5be349c5..4f25dad1 100644 --- a/lib/components/adaptive/adaptive_pop_sheet_list.dart +++ b/lib/components/adaptive/adaptive_pop_sheet_list.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart' show showModalBottomSheet; import 'package:shadcn_flutter/shadcn_flutter.dart'; import 'package:shadcn_flutter/shadcn_flutter_extension.dart'; import 'package:spotube/collections/spotube_icons.dart'; @@ -26,7 +25,7 @@ class AdaptiveMenuButton extends MenuButton { /// An adaptive widget that shows a [PopupMenuButton] when screen size is above /// or equal to 640px -/// In smaller screen, a [IconButton] with a [showModalBottomSheet] is shown +/// In smaller screen, a [IconButton] with a [openDrawer] is shown class AdaptivePopSheetList extends StatelessWidget { final List> Function(BuildContext context) items; final Widget? icon; @@ -102,15 +101,13 @@ class AdaptivePopSheetList extends StatelessWidget { return; } - showModalBottomSheet( + await openDrawer( context: context, - enableDrag: true, + draggable: true, showDragHandle: true, - useRootNavigator: true, - shape: RoundedRectangleBorder( - borderRadius: context.theme.borderRadiusMd, - ), - backgroundColor: context.theme.colorScheme.card, + position: OverlayPosition.bottom, + borderRadius: context.theme.borderRadiusMd, + transformBackdrop: false, builder: (context) { final children = childrenModified(context); return ListView.builder( @@ -127,7 +124,7 @@ class AdaptivePopSheetList extends StatelessWidget { onPressed: () { data.onPressed?.call(context); if (data.autoClose) { - Navigator.of(context).pop(); + closeDrawer(context); } }, leading: data.leading, diff --git a/lib/components/track_presentation/presentation_actions.dart b/lib/components/track_presentation/presentation_actions.dart index 4948cf69..bbeb90a5 100644 --- a/lib/components/track_presentation/presentation_actions.dart +++ b/lib/components/track_presentation/presentation_actions.dart @@ -74,6 +74,26 @@ class TrackPresentationActionsSection extends HookConsumerWidget { ref.watch(presentationStateProvider(options.collection).notifier); final selectedTracks = state.selectedTracks; + Future actionDownloadTracks({ + required BuildContext context, + required List tracks, + required String action, + }) async { + final confirmed = audioSource == AudioSource.piped || + (await showDialog( + context: context, + builder: (context) { + return const ConfirmDownloadDialog(); + }, + ) ?? + false); + if (confirmed != true) return; + downloader.batchAddToQueue(tracks); + notifier.deselectAllTracks(); + if (!context.mounted) return; + showToastForAction(context, action, tracks.length); + } + return AdaptivePopSheetList( tooltip: context.l10n.more_actions, headings: [ @@ -95,22 +115,12 @@ class TrackPresentationActionsSection extends HookConsumerWidget { switch (action) { case "download": - { - final confirmed = audioSource == AudioSource.piped || - (await showDialog( - context: context, - builder: (context) { - return const ConfirmDownloadDialog(); - }, - ) ?? - false); - if (confirmed != true) return; - downloader.batchAddToQueue(tracks); - notifier.deselectAllTracks(); - if (!context.mounted) return; - showToastForAction(context, action, tracks.length); - break; - } + await actionDownloadTracks( + context: context, + tracks: tracks, + action: action, + ); + break; case "add-to-playlist": { if (context.mounted) { diff --git a/lib/components/track_presentation/presentation_top.dart b/lib/components/track_presentation/presentation_top.dart index 8da2f51c..5935fa13 100644 --- a/lib/components/track_presentation/presentation_top.dart +++ b/lib/components/track_presentation/presentation_top.dart @@ -57,7 +57,7 @@ class TrackPresentationTopSection extends HookConsumerWidget { Tooltip( tooltip: TooltipContainer( child: Text(context.l10n.shuffle_playlist), - ), + ).call, child: IconButton.secondary( icon: isLoading ? const Center( @@ -73,7 +73,7 @@ class TrackPresentationTopSection extends HookConsumerWidget { Tooltip( tooltip: TooltipContainer( child: Text(context.l10n.add_to_queue), - ), + ).call, child: IconButton.secondary( icon: const Icon(SpotubeIcons.queueAdd), enabled: !isLoading && !isActive, @@ -126,7 +126,7 @@ class TrackPresentationTopSection extends HookConsumerWidget { Tooltip( tooltip: TooltipContainer( child: Text(context.l10n.share), - ), + ).call, child: IconButton.outline( icon: const Icon(SpotubeIcons.share), size: ButtonSize.small, diff --git a/lib/components/track_tile/track_options.dart b/lib/components/track_tile/track_options.dart index 05e67d02..949fcc8b 100644 --- a/lib/components/track_tile/track_options.dart +++ b/lib/components/track_tile/track_options.dart @@ -91,24 +91,14 @@ class TrackOptions extends HookConsumerWidget { ) { /// showDialog doesn't work for some reason. So we have to /// manually push a Dialog Route in the Navigator to get it working - Navigator.push( - context, - DialogRoute( - alignment: Alignment.bottomCenter, - transitionBuilder: (context, animation, secondaryAnimation, child) { - return FadeTransition(opacity: animation, child: child); - }, - context: context, - barrierColor: Colors.black.withValues(alpha: 0.5), - builder: (context) { - return Center( - child: PlaylistAddTrackDialog( - tracks: [track], - openFromPlaylist: playlistId, - ), - ); - }, - ), + showDialog( + context: context, + builder: (context) { + return PlaylistAddTrackDialog( + tracks: [track], + openFromPlaylist: playlistId, + ); + }, ); } @@ -338,6 +328,7 @@ class TrackOptions extends HookConsumerWidget { } }, icon: icon ?? const Icon(SpotubeIcons.moreHorizontal), + variance: ButtonVariance.outline, headings: [ Basic( leading: AspectRatio( diff --git a/lib/modules/player/player.dart b/lib/modules/player/player.dart index ac077be6..b02910e9 100644 --- a/lib/modules/player/player.dart +++ b/lib/modules/player/player.dart @@ -132,7 +132,7 @@ class PlayerView extends HookConsumerWidget { Tooltip( tooltip: TooltipContainer( child: Text(context.l10n.details), - ), + ).call, child: IconButton.ghost( icon: const Icon(SpotubeIcons.info, size: 18), onPressed: currentTrack == null diff --git a/lib/modules/player/player_actions.dart b/lib/modules/player/player_actions.dart index f3d0a94a..53023a10 100644 --- a/lib/modules/player/player_actions.dart +++ b/lib/modules/player/player_actions.dart @@ -82,7 +82,7 @@ class PlayerActions extends HookConsumerWidget { children: [ if (showQueue) Tooltip( - tooltip: TooltipContainer(child: Text(context.l10n.queue)), + tooltip: TooltipContainer(child: Text(context.l10n.queue)).call, child: IconButton.ghost( icon: const Icon(SpotubeIcons.queue), enabled: playlist.activeTrack != null, @@ -119,7 +119,8 @@ class PlayerActions extends HookConsumerWidget { if (!isLocalTrack) Tooltip( tooltip: TooltipContainer( - child: Text(context.l10n.alternative_track_sources)), + child: Text(context.l10n.alternative_track_sources), + ).call, child: IconButton.ghost( enabled: playlist.activeTrack != null, icon: const Icon(SpotubeIcons.alternativeRoute), @@ -160,7 +161,8 @@ class PlayerActions extends HookConsumerWidget { else Tooltip( tooltip: - TooltipContainer(child: Text(context.l10n.download_track)), + TooltipContainer(child: Text(context.l10n.download_track)) + .call, child: IconButton.ghost( icon: Icon( isDownloaded ? SpotubeIcons.done : SpotubeIcons.download,