loading spaces

This commit is contained in:
Henry Hiles 2025-11-10 21:50:21 -05:00
commit 65028a1231
No known key found for this signature in database
14 changed files with 629 additions and 86 deletions

View file

@ -1,21 +1,22 @@
import "dart:io";
import "package:color_hash/color_hash.dart";
import "package:flutter/material.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:nexus/controllers/spaces_controller.dart";
class Sidebar extends HookWidget {
class Sidebar extends HookConsumerWidget {
const Sidebar({super.key});
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final index = useState(0);
return Drawer(
shape: Border(),
child: Row(
children: [
NavigationRail(
scrollable: true,
useIndicator: false,
labelType: NavigationRailLabelType.none,
onDestinationSelected: (value) => index.value = value,
destinations: [
NavigationRailDestination(
@ -28,11 +29,39 @@ class Sidebar extends HookWidget {
label: Text("Messages"),
padding: EdgeInsets.only(top: 12),
),
NavigationRailDestination(
icon: Image.file(File("assets/icon.png"), width: 40),
label: Text("Space 1"),
padding: EdgeInsets.only(top: 12),
),
...ref
.watch(SpacesController.provider)
.when(
loading: () => [],
error: (error, stack) {
debugPrintStack(
label: error.toString(),
stackTrace: stack,
);
throw error;
},
data: (spaces) => spaces.map(
(space) => NavigationRailDestination(
icon: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)),
child: SizedBox(
width: 40,
height: 40,
child:
space.avatar ??
ColoredBox(
color: ColorHash(space.roomData.name).color,
child: Center(
child: Text(space.roomData.name[0]),
),
),
),
),
label: Text(space.roomData.name),
padding: EdgeInsets.only(top: 12),
),
),
),
],
selectedIndex: index.value,
),
@ -44,6 +73,7 @@ class Sidebar extends HookWidget {
backgroundColor: Colors.transparent,
),
body: NavigationRail(
scrollable: true,
backgroundColor: Colors.transparent,
extended: true,
destinations: [