room switching working
This commit is contained in:
parent
d1f070e5c8
commit
07a032bbf0
5 changed files with 36 additions and 13 deletions
|
|
@ -9,7 +9,10 @@ class CurrentRoomController extends AsyncNotifier<FullRoom> {
|
||||||
SpacesController.provider.future,
|
SpacesController.provider.future,
|
||||||
))[0].children[0].roomData.fullRoom;
|
))[0].children[0].roomData.fullRoom;
|
||||||
|
|
||||||
void set(FullRoom room) => state = AsyncValue.data(room);
|
Future<void> set(FullRoom room) async {
|
||||||
|
await future;
|
||||||
|
state = AsyncValue.data(room);
|
||||||
|
}
|
||||||
|
|
||||||
static final provider =
|
static final provider =
|
||||||
AsyncNotifierProvider<CurrentRoomController, FullRoom>(
|
AsyncNotifierProvider<CurrentRoomController, FullRoom>(
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import "package:dynamic_system_colors/dynamic_system_colors.dart";
|
||||||
import "package:window_size/window_size.dart";
|
import "package:window_size/window_size.dart";
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
ScaledWidgetsFlutterBinding.ensureInitialized(scaleFactor: (_) => 1.4);
|
ScaledWidgetsFlutterBinding.ensureInitialized(scaleFactor: (_) => 1.3);
|
||||||
|
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
await windowManager.waitUntilReadyToShow(
|
await windowManager.waitUntilReadyToShow(
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import "package:color_hash/color_hash.dart";
|
import "package:color_hash/color_hash.dart";
|
||||||
import "package:flutter/widgets.dart";
|
import "package:flutter/widgets.dart";
|
||||||
|
|
||||||
class Avatar extends StatelessWidget {
|
class RoomAvatar extends StatelessWidget {
|
||||||
final Widget? avatar;
|
final Widget? avatar;
|
||||||
final String title;
|
final String title;
|
||||||
final Widget? fallback;
|
final Widget? fallback;
|
||||||
const Avatar(this.avatar, this.title, {this.fallback, super.key});
|
const RoomAvatar(this.avatar, this.title, {this.fallback, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => ClipRRect(
|
Widget build(BuildContext context) => ClipRRect(
|
||||||
|
|
@ -14,6 +14,7 @@ import "package:nexus/controllers/current_room_controller.dart";
|
||||||
import "package:nexus/controllers/room_chat_controller.dart";
|
import "package:nexus/controllers/room_chat_controller.dart";
|
||||||
import "package:nexus/helpers/extension_helper.dart";
|
import "package:nexus/helpers/extension_helper.dart";
|
||||||
import "package:nexus/helpers/launch_helper.dart";
|
import "package:nexus/helpers/launch_helper.dart";
|
||||||
|
import "package:nexus/widgets/room_avatar.dart";
|
||||||
|
|
||||||
class RoomChat extends HookConsumerWidget {
|
class RoomChat extends HookConsumerWidget {
|
||||||
final bool isDesktop;
|
final bool isDesktop;
|
||||||
|
|
@ -39,7 +40,19 @@ class RoomChat extends HookConsumerWidget {
|
||||||
? null
|
? null
|
||||||
: DrawerButton(onPressed: Scaffold.of(context).openDrawer),
|
: DrawerButton(onPressed: Scaffold.of(context).openDrawer),
|
||||||
actionsPadding: EdgeInsets.symmetric(horizontal: 8),
|
actionsPadding: EdgeInsets.symmetric(horizontal: 8),
|
||||||
title: Text(room.title),
|
title: Row(
|
||||||
|
children: [
|
||||||
|
RoomAvatar(
|
||||||
|
room.avatar,
|
||||||
|
room.title,
|
||||||
|
fallback: Icon(Icons.numbers),
|
||||||
|
),
|
||||||
|
SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Text(room.title, overflow: TextOverflow.ellipsis),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
if (!(Platform.isAndroid || Platform.isIOS))
|
if (!(Platform.isAndroid || Platform.isIOS))
|
||||||
IconButton(
|
IconButton(
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||||
import "package:nexus/controllers/current_room_controller.dart";
|
import "package:nexus/controllers/current_room_controller.dart";
|
||||||
import "package:nexus/controllers/spaces_controller.dart";
|
import "package:nexus/controllers/spaces_controller.dart";
|
||||||
import "package:nexus/helpers/extension_helper.dart";
|
import "package:nexus/helpers/extension_helper.dart";
|
||||||
import "package:nexus/widgets/avatar.dart";
|
import "package:nexus/widgets/room_avatar.dart";
|
||||||
|
|
||||||
class Sidebar extends HookConsumerWidget {
|
class Sidebar extends HookConsumerWidget {
|
||||||
const Sidebar({super.key});
|
const Sidebar({super.key});
|
||||||
|
|
@ -13,6 +13,7 @@ class Sidebar extends HookConsumerWidget {
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final selectedSpace = useState(0);
|
final selectedSpace = useState(0);
|
||||||
final selectedRoom = useState(0);
|
final selectedRoom = useState(0);
|
||||||
|
|
||||||
return Drawer(
|
return Drawer(
|
||||||
shape: Border(),
|
shape: Border(),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
@ -27,11 +28,17 @@ class Sidebar extends HookConsumerWidget {
|
||||||
},
|
},
|
||||||
data: (spaces) => NavigationRail(
|
data: (spaces) => NavigationRail(
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
onDestinationSelected: (value) => selectedSpace.value = value,
|
onDestinationSelected: (value) {
|
||||||
|
selectedSpace.value = value;
|
||||||
|
selectedRoom.value = 0;
|
||||||
|
ref
|
||||||
|
.watch(CurrentRoomController.provider.notifier)
|
||||||
|
.set(spaces[selectedSpace.value].children[0]);
|
||||||
|
},
|
||||||
destinations: spaces
|
destinations: spaces
|
||||||
.map(
|
.map(
|
||||||
(space) => NavigationRailDestination(
|
(space) => NavigationRailDestination(
|
||||||
icon: Avatar(space.avatar, space.title),
|
icon: RoomAvatar(space.avatar, space.title),
|
||||||
label: Text(space.title),
|
label: Text(space.title),
|
||||||
padding: EdgeInsets.only(top: 4),
|
padding: EdgeInsets.only(top: 4),
|
||||||
),
|
),
|
||||||
|
|
@ -51,7 +58,7 @@ class Sidebar extends HookConsumerWidget {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Avatar(space.avatar, space.title),
|
RoomAvatar(space.avatar, space.title),
|
||||||
SizedBox(width: 12),
|
SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|
@ -67,10 +74,13 @@ class Sidebar extends HookConsumerWidget {
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
extended: true,
|
extended: true,
|
||||||
|
selectedIndex: space.children.isEmpty
|
||||||
|
? null
|
||||||
|
: selectedRoom.value,
|
||||||
destinations: space.children
|
destinations: space.children
|
||||||
.map(
|
.map(
|
||||||
(room) => NavigationRailDestination(
|
(room) => NavigationRailDestination(
|
||||||
icon: Avatar(
|
icon: RoomAvatar(
|
||||||
room.avatar,
|
room.avatar,
|
||||||
room.title,
|
room.title,
|
||||||
fallback: selectedSpace.value == 1
|
fallback: selectedSpace.value == 1
|
||||||
|
|
@ -87,9 +97,6 @@ class Sidebar extends HookConsumerWidget {
|
||||||
.watch(CurrentRoomController.provider.notifier)
|
.watch(CurrentRoomController.provider.notifier)
|
||||||
.set(space.children[value]);
|
.set(space.children[value]);
|
||||||
},
|
},
|
||||||
selectedIndex: space.children.isEmpty
|
|
||||||
? null
|
|
||||||
: selectedRoom.value,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue