spotube/lib/pages/settings/sections/downloads.dart
Blake Leonard f423c20063
feat: add one additional library folder
This folder just doesn't get downloaded to.
I think I'm going to rework it so that it can be multiple folders,
but I'm going to commit my progress so far anyway.

Signed-off-by: Blake Leonard <me@blakes.dev>
2024-05-09 13:25:32 -04:00

79 lines
2.9 KiB
Dart

import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/settings/section_card_with_heading.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
import 'package:spotube/utils/platform.dart';
class SettingsDownloadsSection extends HookConsumerWidget {
const SettingsDownloadsSection({super.key});
@override
Widget build(BuildContext context, ref) {
final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final preferences = ref.watch(userPreferencesProvider);
final pickDownloadLocation = useCallback(() async {
if (kIsMobile || kIsMacOS) {
final dirStr = await FilePicker.platform.getDirectoryPath(
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
preferencesNotifier.setDownloadLocation(dirStr);
} else {
String? dirStr = await getDirectoryPath(
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
preferencesNotifier.setDownloadLocation(dirStr);
}
}, [preferences.downloadLocation]);
final pickLocalLibraryLocation = useCallback(() async {
if (DesktopTools.platform.isMobile || DesktopTools.platform.isMacOS) {
final dirStr = await FilePicker.platform.getDirectoryPath(
initialDirectory: preferences.localLibraryLocation,
);
if (dirStr == null) return;
preferencesNotifier.setLocalLibraryLocation(dirStr);
} else {
String? dirStr = await getDirectoryPath(
initialDirectory: preferences.localLibraryLocation,
);
if (dirStr == null) return;
preferencesNotifier.setLocalLibraryLocation(dirStr);
}
}, [preferences.localLibraryLocation]);
return SectionCardWithHeading(
heading: context.l10n.downloads,
children: [
ListTile(
leading: const Icon(SpotubeIcons.download),
title: Text(context.l10n.download_location),
subtitle: Text(preferences.downloadLocation),
trailing: FilledButton(
onPressed: pickDownloadLocation,
child: const Icon(SpotubeIcons.folder),
),
onTap: pickDownloadLocation,
),
ListTile(
leading: const Icon(SpotubeIcons.folder),
title: Text(context.l10n.local_library_location),
subtitle: Text(preferences.localLibraryLocation),
trailing: FilledButton(
onPressed: pickLocalLibraryLocation,
child: const Icon(SpotubeIcons.folder),
),
onTap: pickLocalLibraryLocation,
),
],
);
}
}