feat: refactor LibraryBrowserPage to use CustomScrollView and enhance app bar with dynamic library icon and title

This commit is contained in:
Dr.Blank 2025-04-19 19:14:39 +05:30
parent 98e8ffb021
commit f82bcab2e0
No known key found for this signature in database
GPG key ID: BA5F87FF0560C57B

View file

@ -1,38 +1,71 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:vaani/router/router.dart'; import 'package:vaani/api/library_provider.dart' show currentLibraryProvider;
import 'package:vaani/features/you/view/widgets/library_switch_chip.dart'
show showLibrarySwitcher;
import 'package:vaani/router/router.dart' show Routes;
import 'package:vaani/shared/icons/abs_icons.dart' show AbsIcons;
import 'package:vaani/shared/widgets/not_implemented.dart'
show showNotImplementedToast;
class LibraryBrowserPage extends HookConsumerWidget { class LibraryBrowserPage extends HookConsumerWidget {
const LibraryBrowserPage({super.key}); const LibraryBrowserPage({super.key});
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final currentLibrary = ref.watch(currentLibraryProvider).valueOrNull;
// Determine the icon to use, with a fallback
final IconData libraryIconData =
AbsIcons.getIconByName(currentLibrary?.icon) ?? Icons.library_books;
// Determine the title text
final String appBarTitle = '${currentLibrary?.name ?? 'Your'} Library';
return Scaffold( return Scaffold(
appBar: AppBar( // Use CustomScrollView to enable slivers
title: const Text('Library'), body: CustomScrollView(
backgroundColor: Colors.transparent, slivers: <Widget>[
SliverAppBar(
pinned: true,
// floating: true, // Optional: uncomment if you want floating behavior
// snap:
// true, // Optional: uncomment if you want snapping behavior (usually with floating: true)
leading: IconButton(
icon: Icon(libraryIconData),
tooltip: 'Switch Library', // Helpful tooltip for users
onPressed: () {
showLibrarySwitcher(context, ref);
},
), ),
// a list redirecting to authors, genres, and series pages title: Text(appBarTitle),
body: ListView( ),
children: [ SliverList(
delegate: SliverChildListDelegate(
[
ListTile( ListTile(
title: const Text('Authors'), title: const Text('Authors'),
leading: const Icon(Icons.person), leading: const Icon(Icons.person),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () {}, onTap: () {
showNotImplementedToast(context);
},
), ),
ListTile( ListTile(
title: const Text('Genres'), title: const Text('Genres'),
leading: const Icon(Icons.category), leading: const Icon(Icons.category),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () {}, onTap: () {
showNotImplementedToast(context);
},
), ),
ListTile( ListTile(
title: const Text('Series'), title: const Text('Series'),
leading: const Icon(Icons.list), leading: const Icon(Icons.list),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () {}, onTap: () {
showNotImplementedToast(context);
},
), ),
// Downloads // Downloads
ListTile( ListTile(
@ -45,6 +78,9 @@ class LibraryBrowserPage extends HookConsumerWidget {
), ),
], ],
), ),
),
],
),
); );
} }
} }