mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
refactor: dialogs to shadcn dialog
This commit is contained in:
parent
af295be8c6
commit
bbad701c07
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:spotube/components/image/universal_image.dart';
|
||||
import 'package:spotube/extensions/constrains.dart';
|
||||
import 'package:spotube/extensions/context.dart';
|
||||
@ -9,13 +8,15 @@ class ConfirmDownloadDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Row(
|
||||
final screenSize = MediaQuery.sizeOf(context);
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: Breakpoints.sm),
|
||||
child: AlertDialog(
|
||||
title: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Text(context.l10n.are_you_sure),
|
||||
const SizedBox(width: 10),
|
||||
const UniversalImage(
|
||||
path:
|
||||
"https://c.tenor.com/kHcmsxlKHEAAAAAM/rock-one-eyebrow-raised-rock-staring.gif",
|
||||
@ -24,10 +25,8 @@ class ConfirmDownloadDialog extends StatelessWidget {
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
content: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
constraints: BoxConstraints(maxWidth: Breakpoints.sm),
|
||||
content: Expanded(
|
||||
flex: screenSize.smAndUp ? 0 : 1,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -61,21 +60,18 @@ class ConfirmDownloadDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
OutlinedButton(
|
||||
Button.outline(
|
||||
child: Text(context.l10n.decline),
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
Button.destructive(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text(context.l10n.accept),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:spotube/extensions/context.dart';
|
||||
|
||||
Future<bool> showPromptDialog({
|
||||
@ -16,13 +16,13 @@ Future<bool> showPromptDialog({
|
||||
content: Text(message),
|
||||
actions: [
|
||||
if (cancelText != null)
|
||||
OutlinedButton(
|
||||
Button.outline(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text(
|
||||
cancelText == "Cancel" ? context.l10n.cancel : cancelText,
|
||||
),
|
||||
),
|
||||
FilledButton(
|
||||
Button.primary(
|
||||
child: Text(okText == "Ok" ? context.l10n.ok : okText),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/extensions/context.dart';
|
||||
@ -13,45 +13,35 @@ class ReplaceDownloadedDialog extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
final groupValue = ref.watch(replaceDownloadedFileState);
|
||||
final theme = Theme.of(context);
|
||||
final replaceAll = ref.watch(replaceDownloadedFileState);
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(context.l10n.track_exists(track.name ?? "")),
|
||||
content: Column(
|
||||
content: RadioGroup(
|
||||
value: groupValue,
|
||||
onChanged: (value) {
|
||||
ref.read(replaceDownloadedFileState.notifier).state = value;
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(context.l10n.do_you_want_to_replace),
|
||||
RadioListTile<bool>(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
activeColor: theme.colorScheme.primary,
|
||||
const Gap(16),
|
||||
RadioItem<bool>(
|
||||
value: true,
|
||||
groupValue: groupValue,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(replaceDownloadedFileState.notifier).state = true;
|
||||
}
|
||||
},
|
||||
title: Text(context.l10n.replace_downloaded_tracks),
|
||||
trailing: Text(context.l10n.replace_downloaded_tracks),
|
||||
),
|
||||
RadioListTile<bool>(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
activeColor: theme.colorScheme.primary,
|
||||
const Gap(8),
|
||||
RadioItem<bool>(
|
||||
value: false,
|
||||
groupValue: groupValue,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(replaceDownloadedFileState.notifier).state = false;
|
||||
}
|
||||
},
|
||||
title: Text(context.l10n.skip_download_tracks),
|
||||
trailing: Text(context.l10n.skip_download_tracks),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
OutlinedButton(
|
||||
Button.outline(
|
||||
onPressed: replaceAll == true
|
||||
? null
|
||||
: () {
|
||||
@ -59,7 +49,7 @@ class ReplaceDownloadedDialog extends ConsumerWidget {
|
||||
},
|
||||
child: Text(context.l10n.skip),
|
||||
),
|
||||
FilledButton(
|
||||
Button.primary(
|
||||
onPressed: replaceAll == false
|
||||
? null
|
||||
: () {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:spotube/extensions/context.dart';
|
||||
import 'package:spotube/provider/connect/clients.dart';
|
||||
|
||||
@ -16,31 +16,31 @@ class SelectDeviceDialog extends HookConsumerWidget {
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(context.l10n.choose_the_device),
|
||||
insetPadding: const EdgeInsets.all(16),
|
||||
content: Column(
|
||||
content: RadioGroup(
|
||||
value: isRemoteService.value,
|
||||
onChanged: (value) {
|
||||
isRemoteService.value = value;
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(context.l10n.multiple_device_connected),
|
||||
RadioListTile.adaptive(
|
||||
title: Text(remoteService.name),
|
||||
const Gap(16),
|
||||
RadioItem(
|
||||
trailing: Text(remoteService.name),
|
||||
value: true,
|
||||
groupValue: isRemoteService.value,
|
||||
onChanged: (value) {
|
||||
isRemoteService.value = value!;
|
||||
},
|
||||
),
|
||||
RadioListTile.adaptive(
|
||||
title: Text(context.l10n.this_device),
|
||||
const Gap(8),
|
||||
RadioItem(
|
||||
trailing: Text(context.l10n.this_device),
|
||||
value: false,
|
||||
groupValue: isRemoteService.value,
|
||||
onChanged: (value) {
|
||||
isRemoteService.value = !value!;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
Button.primary(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(isRemoteService.value);
|
||||
},
|
||||
@ -51,7 +51,8 @@ class SelectDeviceDialog extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> showSelectDeviceDialog(BuildContext context, WidgetRef ref) async {
|
||||
Future<bool?> showSelectDeviceDialog(
|
||||
BuildContext context, WidgetRef ref) async {
|
||||
final connectClients = ref.read(connectClientsProvider);
|
||||
|
||||
if (connectClients.asData?.value.resolvedService == null) {
|
||||
@ -63,5 +64,5 @@ Future<bool> showSelectDeviceDialog(BuildContext context, WidgetRef ref) async {
|
||||
builder: (context) => const SelectDeviceDialog(),
|
||||
);
|
||||
|
||||
return isRemote ?? false;
|
||||
return isRemote;
|
||||
}
|
||||
|
@ -97,12 +97,13 @@ class TrackPresentationActionsSection extends HookConsumerWidget {
|
||||
case "download":
|
||||
{
|
||||
final confirmed = audioSource == AudioSource.piped ||
|
||||
await showDialog(
|
||||
(await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const ConfirmDownloadDialog();
|
||||
},
|
||||
);
|
||||
) ??
|
||||
false);
|
||||
if (confirmed != true) return;
|
||||
downloader.batchAddToQueue(tracks);
|
||||
notifier.deselectAllTracks();
|
||||
|
@ -40,6 +40,7 @@ UseActionCallbacks useActionCallbacks(WidgetRef ref) {
|
||||
if (!context.mounted) return;
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
if (isRemoteDevice == null) return;
|
||||
if (isRemoteDevice) {
|
||||
final allTracks = await options.pagination.onFetchAll();
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
@ -90,6 +91,7 @@ UseActionCallbacks useActionCallbacks(WidgetRef ref) {
|
||||
if (!context.mounted) return;
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
if (isRemoteDevice == null) return;
|
||||
if (isRemoteDevice) {
|
||||
final allTracks = await options.pagination.onFetchAll();
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
|
@ -37,6 +37,7 @@ Future<void> Function(Track track, int index) useTrackTilePlayCallback(
|
||||
}
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
if (isRemoteDevice == null) return;
|
||||
|
||||
if (isRemoteDevice) {
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
|
@ -91,6 +91,7 @@ class AlbumCard extends HookConsumerWidget {
|
||||
if (fetchedTracks.isEmpty || !context.mounted) return;
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
if (isRemoteDevice == null) return;
|
||||
if (isRemoteDevice) {
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
await remotePlayback.load(
|
||||
|
@ -94,6 +94,7 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
if (fetchedInitialTracks.isEmpty || !context.mounted) return;
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
if (isRemoteDevice == null) return;
|
||||
if (isRemoteDevice) {
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
final allTracks = await fetchAllTracks();
|
||||
|
@ -44,6 +44,9 @@ class ArtistPageTopTracks extends HookConsumerWidget {
|
||||
currentTrack ??= tracks.first;
|
||||
|
||||
final isRemoteDevice = await showSelectDeviceDialog(context, ref);
|
||||
|
||||
if (isRemoteDevice == null) return;
|
||||
|
||||
if (isRemoteDevice) {
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
final remotePlaylist = ref.read(queueProvider);
|
||||
|
@ -188,6 +188,7 @@ class ConnectControlPage extends HookConsumerWidget {
|
||||
SliverToBoxAdapter(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 20,
|
||||
children: [
|
||||
Tooltip(
|
||||
tooltip: TooltipContainer(
|
||||
|
@ -55,6 +55,8 @@ class SearchTracksSection extends HookConsumerWidget {
|
||||
final isRemoteDevice =
|
||||
await showSelectDeviceDialog(context, ref);
|
||||
|
||||
if (isRemoteDevice == null) return;
|
||||
|
||||
if (isRemoteDevice) {
|
||||
final remotePlayback = ref.read(connectProvider.notifier);
|
||||
final remotePlaylist = ref.read(queueProvider);
|
||||
|
Loading…
Reference in New Issue
Block a user