redesign sidebar to be m3e

This commit is contained in:
Henry Hiles 2026-06-05 20:38:03 -04:00
commit 895ab3c96f
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
9 changed files with 230 additions and 129 deletions

View file

@ -11,15 +11,11 @@ class AvatarOrHash extends ConsumerWidget {
final Uri? avatar; final Uri? avatar;
final String title; final String title;
final Widget? fallback; final Widget? fallback;
final bool hasBadge;
final int badgeNumber;
final double height; final double height;
const AvatarOrHash( const AvatarOrHash(
this.avatar, this.avatar,
this.title, { this.title, {
this.fallback, this.fallback,
this.badgeNumber = 0,
this.hasBadge = false,
this.height = 24, this.height = 24,
super.key, super.key,
}); });
@ -44,30 +40,24 @@ class AvatarOrHash extends ConsumerWidget {
width: height, width: height,
height: height, height: height,
child: Center( child: Center(
child: Badge( child: ClipRRect(
isLabelVisible: hasBadge, borderRadius: .all(.circular((height - 8) / 2.5)),
label: badgeNumber != 0 ? Text(badgeNumber.toString()) : null, child: SizedBox(
smallSize: 12, width: height,
backgroundColor: Theme.of(context).colorScheme.primary, height: height,
child: ClipRRect( child: parsedAvatar == null
borderRadius: .all(.circular((height - 8) / 2.5)), ? fallback ?? box
child: SizedBox( : Image(
width: height, image: CachedNetworkImage(
height: height, parsedAvatar.toString(),
child: parsedAvatar == null ref.watch(CrossCacheController.provider),
? fallback ?? box headers: ref.headers,
: Image(
image: CachedNetworkImage(
parsedAvatar.toString(),
ref.watch(CrossCacheController.provider),
headers: ref.headers,
),
fit: .cover,
loadingBuilder: (_, child, loadingProgress) =>
loadingProgress == null ? child : fallback ?? box,
errorBuilder: (_, _, _) => fallback ?? box,
), ),
), fit: .cover,
loadingBuilder: (_, child, loadingProgress) =>
loadingProgress == null ? child : fallback ?? box,
errorBuilder: (_, _, _) => fallback ?? box,
),
), ),
), ),
), ),

View file

@ -28,10 +28,10 @@ class MemberList extends HookConsumerWidget {
), ),
); );
final options = { final options = <String, MembershipStatus>{
"Joined": MembershipStatus.join, "Joined": .join,
"Invited": MembershipStatus.invite, "Invited": .invite,
"Banned": MembershipStatus.ban, "Banned": .ban,
}; };
return Drawer( return Drawer(
@ -53,7 +53,7 @@ class MemberList extends HookConsumerWidget {
], ],
), ),
M3EToggleButtonGroup( M3EToggleButtonGroup(
type: M3EButtonGroupType.connected, type: .connected,
selectedIndex: options.values.toIList().indexOf(status.value), selectedIndex: options.values.toIList().indexOf(status.value),
onSelectedIndexChanged: (index) => onSelectedIndexChanged: (index) =>
status.value = options.values.elementAt(index ?? 0), status.value = options.values.elementAt(index ?? 0),
@ -99,7 +99,7 @@ class MemberList extends HookConsumerWidget {
.compareTo(a?.key ?? double.infinity), .compareTo(a?.key ?? double.infinity),
)) ...[ )) ...[
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 4), padding: .symmetric(horizontal: 4),
child: DividerText( child: DividerText(
powerLevel == null powerLevel == null
? "Creators" ? "Creators"

View file

@ -1,6 +1,7 @@
import "package:collection/collection.dart"; import "package:collection/collection.dart";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:hooks_riverpod/hooks_riverpod.dart"; import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
import "package:nexus/controllers/key_controller.dart"; import "package:nexus/controllers/key_controller.dart";
import "package:nexus/controllers/spaces_controller.dart"; import "package:nexus/controllers/spaces_controller.dart";
import "package:nexus/widgets/avatar_or_hash.dart"; import "package:nexus/widgets/avatar_or_hash.dart";
@ -43,82 +44,110 @@ class Sidebar extends HookConsumerWidget {
: indexOfSelectedRoom; : indexOfSelectedRoom;
return Drawer( return Drawer(
width: 340,
shape: Border(), shape: Border(),
child: Row( child: Row(
children: [ children: [
NavigationRail( Theme(
scrollable: true, data: Theme.of(context).copyWith(
onDestinationSelected: (value) { extensions: [
selectedSpaceIdNotifier.set(spaces[value].id); NavigationRailM3ETheme(
selectedRoomIdNotifier.set( itemCollapsedHeight: 48,
spaces[value].children.firstOrNull?.metadata?.id, itemVerticalGap: 0,
); ),
}, ],
destinations: spaces ),
.map( child: Padding(
(space) => NavigationRailDestination( padding: EdgeInsets.only(top: 16),
icon: AvatarOrHash( child: NavigationRailM3E(
space.room?.metadata?.avatar, type: .alwaysCollapse,
fallback: space.icon == null ? null : Icon(space.icon), labelBehavior: .alwaysHide,
space.title, scrollable: true,
hasBadge: space.children.any( onDestinationSelected: (value) {
(room) => room.metadata?.unreadMessages != 0, selectedSpaceIdNotifier.set(spaces[value].id);
), selectedRoomIdNotifier.set(
badgeNumber: space.children.fold( spaces[value].children.firstOrNull?.metadata?.id,
0, );
(previousValue, room) => },
previousValue + sections: [
(room.metadata?.unreadNotifications ?? 0), .new(
), destinations: spaces
), .map(
label: Text(space.title), (space) => NavigationRailM3EDestination(
padding: .only(top: 4), badgeCount: switch (space.children.fold(
), 0,
) (previousValue, room) =>
.toList(), previousValue +
selectedIndex: selectedIndex, (room.metadata?.unreadNotifications ?? 0),
trailingAtBottom: true, )) {
trailing: Padding( 0 =>
padding: .symmetric(vertical: 16), space.children.any(
child: Column( (room) =>
spacing: 8, room.metadata?.unreadMessages != 0,
children: [ )
PopupMenuButton( ? 0
itemBuilder: (_) => [ : null,
PopupMenuItem( int badgeCount => badgeCount,
onTap: () => showDialog( },
context: context, short: true,
builder: (_) => JoinDialog(ref), icon: AvatarOrHash(
), space.room?.metadata?.avatar,
child: ListTile( fallback: space.icon == null
title: Text("Join an existing room (or space)"), ? null
leading: Icon(Icons.numbers), : Icon(space.icon),
), space.title,
), ),
PopupMenuItem( label: space.title,
onTap: null, ),
child: ListTile( )
title: Text("Create a new room"), .toList(),
leading: Icon(Icons.add),
),
),
],
icon: Icon(Icons.add),
),
IconButton(
tooltip: "Explore other rooms",
onPressed: null,
icon: Icon(Icons.explore),
),
IconButton(
tooltip: "Open settings",
onPressed: null,
// () => Navigator.of(
// context,
// ).push(MaterialPageRoute(builder: (_) => SettingsPage())),
icon: Icon(Icons.settings),
), ),
], ],
selectedIndex: selectedIndex,
trailingAtBottom: true,
trailing: Padding(
padding: .symmetric(vertical: 16),
child: Column(
spacing: 8,
children: [
PopupMenuButton(
itemBuilder: (_) => [
PopupMenuItem(
onTap: () => showDialog(
context: context,
builder: (_) => JoinDialog(ref),
),
child: ListTile(
title: Text("Join an existing room (or space)"),
leading: Icon(Icons.numbers),
),
),
PopupMenuItem(
onTap: null,
child: ListTile(
title: Text("Create a new room"),
leading: Icon(Icons.add),
),
),
],
icon: Icon(Icons.add),
),
IconButton(
tooltip: "Explore other rooms",
onPressed: null,
icon: Icon(Icons.explore),
),
IconButton(
tooltip: "Open settings",
onPressed: null,
// () => Navigator.of(
// context,
// ).push(MaterialPageRoute(builder: (_) => SettingsPage())),
icon: Icon(Icons.settings),
),
],
),
),
), ),
), ),
), ),
@ -143,34 +172,54 @@ class Sidebar extends HookConsumerWidget {
), ),
], ],
), ),
body: NavigationRail( body: Theme(
scrollable: true, data: Theme.of(context).copyWith(
backgroundColor: Colors.transparent, extensions: [
extended: true, NavigationRailM3ETheme(
selectedIndex: selectedRoomIndex, itemExpandedHeight: 48,
destinations: selectedSpace.children iconLabelGap: 16,
.map( ),
(room) => NavigationRailDestination( ],
label: Text(room.metadata?.name ?? "Unnamed Room"), ),
icon: AvatarOrHash( child: NavigationRailM3E(
room.metadata?.avatar, expandedWidth: 360,
hasBadge: room.metadata?.unreadMessages != 0, scrollable: true,
badgeNumber: room.metadata?.unreadNotifications ?? 0, background: Colors.transparent,
room.metadata?.name ?? "Unnamed Room", type: .alwaysExpand,
fallback: selectedSpaceId == "dms" selectedIndex: selectedRoomIndex ?? 0,
? null sections: [
: Icon(Icons.numbers), .new(
// space.client.headers, destinations: selectedSpace.children
), .map(
), (room) => NavigationRailM3EDestination(
) label: room.metadata?.name ?? "Unnamed Room",
.toList(), badgeCount: switch (room
onDestinationSelected: (value) { .metadata
selectedRoomIdNotifier.set( ?.unreadNotifications) {
selectedSpace.children[value].metadata?.id, 0 || null =>
); room.metadata?.unreadMessages == 0 ? null : 0,
if (!isDesktop) Navigator.of(context).pop(); int unread => unread,
}, },
icon: AvatarOrHash(
room.metadata?.avatar,
room.metadata?.name ?? "Unnamed Room",
fallback: selectedSpaceId == "dms"
? null
: Icon(Icons.numbers),
// space.client.headers,
),
),
)
.toList(),
),
],
onDestinationSelected: (value) {
selectedRoomIdNotifier.set(
selectedSpace.children[value].metadata?.id,
);
if (!isDesktop) Navigator.of(context).pop();
},
),
), ),
), ),
), ),

View file

@ -6,6 +6,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h>
#include <dynamic_system_colors/dynamic_color_plugin.h> #include <dynamic_system_colors/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h> #include <file_selector_linux/file_selector_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h> #include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
@ -15,6 +16,9 @@
#include <window_manager/window_manager_plugin.h> #include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) dynamic_system_colors_registrar = g_autoptr(FlPluginRegistrar) dynamic_system_colors_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_system_colors_registrar); dynamic_color_plugin_register_with_registrar(dynamic_system_colors_registrar);

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
dynamic_system_colors dynamic_system_colors
file_selector_linux file_selector_linux
media_kit_libs_linux media_kit_libs_linux

View file

@ -121,6 +121,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "8.12.6" version: "8.12.6"
button_m3e:
dependency: transitive
description:
name: button_m3e
sha256: "6754ddeb9068ad2005bd26d5ceabc41268029465095686d7d228296c2e706909"
url: "https://pub.dev"
source: hosted
version: "0.1.2"
characters: characters:
dependency: transitive dependency: transitive
description: description:
@ -273,6 +281,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
dynamic_color:
dependency: transitive
description:
name: dynamic_color
sha256: "43a5a6679649a7731ab860334a5812f2067c2d9ce6452cf069c5e0c25336c17c"
url: "https://pub.dev"
source: hosted
version: "1.8.1"
dynamic_polls: dynamic_polls:
dependency: "direct main" dependency: "direct main"
description: description:
@ -307,6 +323,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.8" version: "2.0.8"
fab_m3e:
dependency: transitive
description:
name: fab_m3e
sha256: e4f5abfa3c8c092005449d56dcac45b85e2dbe9c32789d672c5ed71428e43b59
url: "https://pub.dev"
source: hosted
version: "0.1.1"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -591,6 +615,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.1.2" version: "4.1.2"
icon_button_m3e:
dependency: transitive
description:
name: icon_button_m3e
sha256: c4524d6141a468679821bbb635b833ac6831925d8a6ae4a4511430b0e4ab9c67
url: "https://pub.dev"
source: hosted
version: "0.2.1"
idb_shim: idb_shim:
dependency: transitive dependency: transitive
description: description:
@ -760,6 +792,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.0.3" version: "0.0.3"
m3e_design:
dependency: transitive
description:
name: m3e_design
sha256: "15ff0ef4c43553d855c5e866a9aee8231d44919fe2bb354b1259337bdfd659b4"
url: "https://pub.dev"
source: hosted
version: "0.2.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
@ -888,6 +928,15 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.17.6" version: "0.17.6"
navigation_rail_m3e:
dependency: "direct main"
description:
path: "packages/navigation_rail_m3e"
ref: HEAD
resolved-ref: a403b67b41f6fba7f91273bfd52b4f835872c004
url: "https://github.com/Henry-Hiles/material_3_expressive"
source: git
version: "0.3.5"
node_preamble: node_preamble:
dependency: transitive dependency: transitive
description: description:

View file

@ -66,6 +66,10 @@ dependencies:
measure_size: ^5.0.2 measure_size: ^5.0.2
material_segmented_list: ^1.0.5 material_segmented_list: ^1.0.5
m3e_buttons: ^0.0.3 m3e_buttons: ^0.0.3
navigation_rail_m3e:
git:
url: https://github.com/Henry-Hiles/material_3_expressive
path: packages/navigation_rail_m3e
dev_dependencies: dev_dependencies:
build_runner: 2.15.0 build_runner: 2.15.0

View file

@ -6,6 +6,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <dynamic_system_colors/dynamic_color_plugin_c_api.h> #include <dynamic_system_colors/dynamic_color_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h> #include <file_selector_windows/file_selector_windows.h>
#include <media_kit_libs_windows_video/media_kit_libs_windows_video_plugin_c_api.h> #include <media_kit_libs_windows_video/media_kit_libs_windows_video_plugin_c_api.h>
@ -15,6 +16,8 @@
#include <window_manager/window_manager_plugin.h> #include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
DynamicColorPluginCApiRegisterWithRegistrar( DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
FileSelectorWindowsRegisterWithRegistrar( FileSelectorWindowsRegisterWithRegistrar(

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
dynamic_system_colors dynamic_system_colors
file_selector_windows file_selector_windows
media_kit_libs_windows_video media_kit_libs_windows_video