fluffychat/lib/pages/chat_list/spaces_drawer.dart
TheOneWithTheBraid 77661f1ead feat: space navigation enhancements
- add ravigation rail on large screens
- refactor space hierarchy dummy code
- add material 3 like radius to spaces drawer
- rename column router to catch the application-specific code inside

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
2022-07-17 17:52:19 +00:00

105 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/pages/chat_list/spaces_entry.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'chat_list.dart';
class SpacesDrawer extends StatelessWidget {
final ChatListController controller;
const SpacesDrawer({Key? key, required this.controller}) : super(key: key);
/// PLACEHOLDER for later computation of space hierarchy mapping
///
/// TODO(TheOeWithTheBraid): implement space hierarchy
static Map<SpacesEntry, dynamic> getSpaceHierarchy(
ChatListController controller) {
return Map.fromEntries(
controller.spacesEntries.map((e) => MapEntry(e, null)));
}
@override
Widget build(BuildContext context) {
/// keep this implementation in sync with [ChatListBodyContainer]
final currentIndex = controller.spacesEntries.indexWhere((space) =>
controller.activeSpacesEntry.runtimeType == space.runtimeType &&
(controller.activeSpaceId == space.getSpace(context)?.id));
final Map<SpacesEntry, dynamic> spaceHierarchy =
SpacesDrawer.getSpaceHierarchy(controller);
return ListView.builder(
itemCount: spaceHierarchy.length + 1,
itemBuilder: (context, i) {
if (i == spaceHierarchy.length) {
return ListTile(
leading: CircleAvatar(
radius: Avatar.defaultSize / 2,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).colorScheme.onSecondary,
child: const Icon(
Icons.archive_outlined,
),
),
title: Text(L10n.of(context)!.archive),
onTap: () {
Scaffold.of(context).closeDrawer();
VRouter.of(context).to('/archive');
},
);
}
final space = spaceHierarchy.keys.toList()[i];
final room = space.getSpace(context);
final active = currentIndex == i;
return ListTile(
selected: active,
leading: room == null
? CircleAvatar(
child: space.getIcon(active),
radius: Avatar.defaultSize / 2,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context).colorScheme.onSecondary,
)
: Avatar(
mxContent: room.avatar,
name: space.getName(context),
),
title: Text(
space.getName(context),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: room?.topic.isEmpty ?? true
? null
: Tooltip(
message: room!.topic,
child: Text(
room.topic.replaceAll('\n', ' '),
softWrap: false,
overflow: TextOverflow.fade,
),
),
onTap: () => controller.setActiveSpacesEntry(
context,
space,
),
trailing: room != null
? SizedBox(
width: 32,
child: IconButton(
splashRadius: 24,
icon: const Icon(Icons.edit_outlined),
tooltip: L10n.of(context)!.edit,
onPressed: () => controller.editSpace(context, room.id),
),
)
: const Icon(Icons.arrow_forward_ios_outlined),
);
},
);
}
}