parent
dbf30c3706
commit
d37ec2878b
21 changed files with 561 additions and 147 deletions
|
|
@ -1,47 +1,47 @@
|
|||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/controllers/notification_request.dart";
|
||||
import "package:nexus/controllers/sidebar_page.dart";
|
||||
import "package:nexus/models/nav_page.dart";
|
||||
import "package:nexus/models/sidebar_page.dart";
|
||||
import "package:nexus/widgets/invites_list.dart";
|
||||
import "package:nexus/widgets/notifications_list.dart";
|
||||
import "package:nexus/widgets/room_list.dart";
|
||||
|
||||
class const Sidebar({super.key}) extends HookConsumerWidget {
|
||||
class const Sidebar({super.key}) extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
const pages = <NavPage>[RoomList(), NotificationsList(), InvitesList()];
|
||||
final notificationsIndex = pages.indexWhere(
|
||||
(page) => page is NotificationsList,
|
||||
final selected = ref.watch(SidebarPageController.provider);
|
||||
final pages = SidebarPage.values.map<NavPage>(
|
||||
(page) => switch (page) {
|
||||
.rooms => const RoomList(),
|
||||
.notifications => const NotificationsList(),
|
||||
.invites => const InvitesList(),
|
||||
},
|
||||
);
|
||||
|
||||
final selectedIndex = useState(
|
||||
ref.read(NotificationRequestController.provider) == null
|
||||
? 0
|
||||
: notificationsIndex,
|
||||
);
|
||||
|
||||
ref.listen(NotificationRequestController.provider, (_, next) {
|
||||
if (next != null) selectedIndex.value = notificationsIndex;
|
||||
});
|
||||
|
||||
return Drawer(
|
||||
width: 330,
|
||||
shape: Border(),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: pages[selectedIndex.value],
|
||||
body: pages.elementAt(selected.index),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: selectedIndex.value,
|
||||
destinations: pages
|
||||
.map(
|
||||
(element) => NavigationDestination(
|
||||
icon: Icon(element.icon),
|
||||
label: element.title,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onDestinationSelected: (value) => selectedIndex.value = value,
|
||||
selectedIndex: selected.index,
|
||||
destinations: pages.map((page) {
|
||||
final badgeCount = page.badgeCount(ref);
|
||||
|
||||
return NavigationDestination(
|
||||
icon: Badge.count(
|
||||
count: badgeCount ?? 0,
|
||||
isLabelVisible: badgeCount != null,
|
||||
child: Icon(page.icon),
|
||||
),
|
||||
label: page.title,
|
||||
);
|
||||
}).toList(),
|
||||
onDestinationSelected: (index) => ref
|
||||
.read(SidebarPageController.provider.notifier)
|
||||
.set(SidebarPage.values[index]),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue