refactor: remove redundant library management in settings

This commit is contained in:
edde746
2025-11-04 08:21:52 +01:00
parent f0035d1335
commit 5126b67c9c
-102
View File
@@ -46,20 +46,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
});
}
Future<void> _unhideLibrary(String libraryKey) async {
// Unhide library using provider
final hiddenLibrariesProvider = Provider.of<HiddenLibrariesProvider>(
context,
listen: false,
);
await hiddenLibrariesProvider.unhideLibrary(libraryKey);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Library shown')),
);
}
}
@override
Widget build(BuildContext context) {
@@ -77,8 +63,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
delegate: SliverChildListDelegate([
_buildAppearanceSection(),
const SizedBox(height: 24),
_buildLibraryManagementSection(),
const SizedBox(height: 24),
_buildVideoPlaybackSection(),
const SizedBox(height: 24),
_buildKeyboardShortcutsSection(),
@@ -151,92 +135,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
Widget _buildLibraryManagementSection() {
// Watch for hidden libraries changes to trigger rebuild
final hiddenLibrariesProvider = context.watch<HiddenLibrariesProvider>();
final hiddenKeys = hiddenLibrariesProvider.hiddenLibraryKeys;
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Library Management',
style: Theme.of(
context,
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
),
),
if (hiddenKeys.isEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Text(
'No hidden libraries',
style: TextStyle(color: Colors.grey[600]),
),
)
else
// Use FutureBuilder to fetch library details for hidden keys
FutureBuilder<List<PlexLibrary>>(
future: _fetchHiddenLibraries(hiddenKeys),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Padding(
padding: EdgeInsets.all(16),
child: Center(child: CircularProgressIndicator()),
);
}
if (snapshot.hasError || !snapshot.hasData) {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Text(
'Error loading hidden libraries',
style: TextStyle(color: Colors.grey[600]),
),
);
}
final hiddenLibraries = snapshot.data!;
return Column(
children: hiddenLibraries.map((library) {
return ListTile(
leading: const Icon(Icons.visibility_off),
title: Text(library.title),
subtitle: Text('${library.type} library'),
trailing: TextButton(
onPressed: () => _unhideLibrary(library.key),
child: const Text('Show'),
),
);
}).toList(),
);
},
),
],
),
);
}
Future<List<PlexLibrary>> _fetchHiddenLibraries(Set<String> hiddenKeys) async {
final clientProvider = Provider.of<PlexClientProvider>(
context,
listen: false,
);
final client = clientProvider.client;
if (client == null) {
return [];
}
final allLibraries = await client.getLibraries();
return allLibraries
.where((lib) => hiddenKeys.contains(lib.key))
.toList();
}
Widget _buildVideoPlaybackSection() {
return Card(
child: Column(