💄 Optimize settings screen

This commit is contained in:
2025-12-19 22:49:50 +08:00
parent e820fb08de
commit ac4ceb3960

View File

@@ -3,6 +3,7 @@ import 'package:groovybox/providers/settings_provider.dart';
import 'package:groovybox/providers/watch_folder_provider.dart'; import 'package:groovybox/providers/watch_folder_provider.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:styled_widget/styled_widget.dart';
class SettingsScreen extends ConsumerWidget { class SettingsScreen extends ConsumerWidget {
const SettingsScreen({super.key}); const SettingsScreen({super.key});
@@ -15,15 +16,19 @@ class SettingsScreen extends ConsumerWidget {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('Settings')), appBar: AppBar(title: const Text('Settings')),
body: settingsAsync.when( body: settingsAsync.when(
data: (settings) => SingleChildScrollView( data: (settings) => Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 640),
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
spacing: 16,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Auto Scan Section // Auto Scan Section
Card( Card(
child: Padding( margin: EdgeInsets.zero,
padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -33,13 +38,15 @@ class SettingsScreen extends ConsumerWidget {
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ).padding(horizontal: 16, bottom: 8, top: 16),
const SizedBox(height: 8),
SwitchListTile( SwitchListTile(
title: const Text('Auto-scan music libraries'), title: const Text('Auto-scan music libraries'),
subtitle: const Text( subtitle: const Text(
'Automatically scan music libraries for new music files', 'Automatically scan music libraries for new music files',
), ),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
value: settings.autoScan, value: settings.autoScan,
onChanged: (value) { onChanged: (value) {
ref.read(autoScanProvider.notifier).update(value); ref.read(autoScanProvider.notifier).update(value);
@@ -50,6 +57,9 @@ class SettingsScreen extends ConsumerWidget {
subtitle: const Text( subtitle: const Text(
'Monitor music libraries for file changes', 'Monitor music libraries for file changes',
), ),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
value: settings.watchForChanges, value: settings.watchForChanges,
onChanged: (value) { onChanged: (value) {
ref ref
@@ -57,19 +67,18 @@ class SettingsScreen extends ConsumerWidget {
.update(value); .update(value);
}, },
), ),
const SizedBox(height: 8),
], ],
), ),
), ),
),
const SizedBox(height: 16),
// Watch Folders Section // Watch Folders Section
Card( Card(
child: Padding( margin: EdgeInsets.zero,
padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -84,25 +93,38 @@ class SettingsScreen extends ConsumerWidget {
Row( Row(
children: [ children: [
IconButton( IconButton(
onPressed: () => _scanLibraries(context, ref), onPressed: () =>
_scanLibraries(context, ref),
icon: const Icon(Icons.refresh), icon: const Icon(Icons.refresh),
tooltip: 'Scan Libraries', tooltip: 'Scan Libraries',
visualDensity: const VisualDensity(
horizontal: -4,
vertical: -4,
),
), ),
IconButton( IconButton(
onPressed: () => _addMusicLibrary(context, ref), onPressed: () =>
_addMusicLibrary(context, ref),
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
tooltip: 'Add Music Library', tooltip: 'Add Music Library',
visualDensity: const VisualDensity(
horizontal: -4,
vertical: -4,
),
), ),
], ],
), ),
], ],
), ),
const SizedBox(height: 8),
const Text( const Text(
'Add folder libraries to index music files. Files will be copied to internal storage for playback.', 'Add folder libraries to index music files. Files will be copied to internal storage for playback.',
style: TextStyle(color: Colors.grey, fontSize: 14), style: TextStyle(
color: Colors.grey,
fontSize: 14,
), ),
const SizedBox(height: 8), ),
],
).padding(horizontal: 16, top: 16, bottom: 8),
watchFoldersAsync.when( watchFoldersAsync.when(
data: (folders) => folders.isEmpty data: (folders) => folders.isEmpty
? const Text( ? const Text(
@@ -111,13 +133,17 @@ class SettingsScreen extends ConsumerWidget {
color: Colors.grey, color: Colors.grey,
fontSize: 14, fontSize: 14,
), ),
) ).padding(horizontal: 16, vertical: 8)
: Column( : Column(
children: folders children: folders
.map( .map(
(folder) => ListTile( (folder) => ListTile(
title: Text(folder.name), title: Text(folder.name),
subtitle: Text(folder.path), subtitle: Text(folder.path),
contentPadding: const EdgeInsets.only(
left: 16,
right: 16,
),
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@@ -156,13 +182,15 @@ class SettingsScreen extends ConsumerWidget {
error: (error, _) => error: (error, _) =>
Text('Error loading libraries: $error'), Text('Error loading libraries: $error'),
), ),
const SizedBox(height: 8),
], ],
), ),
), ),
),
], ],
), ),
), ),
),
),
loading: () => const Center(child: CircularProgressIndicator()), loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => error: (error, stack) =>
Center(child: Text('Error loading settings: $error')), Center(child: Text('Error loading settings: $error')),