parent
ed2d08ed40
commit
76d78596cd
12 changed files with 141 additions and 49 deletions
21
lib/widgets/adaptive_menu_button.dart
Normal file
21
lib/widgets/adaptive_menu_button.dart
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_menu.dart";
|
||||
|
||||
/// Like [PopupMenuButton], but shows a bottom sheet on mobile.
|
||||
class const AdaptiveMenuButton({
|
||||
required final Widget icon,
|
||||
required final List<PopupMenuEntry> Function(BuildContext context)
|
||||
itemBuilder,
|
||||
final String? tooltip,
|
||||
final bool enabled = true,
|
||||
super.key,
|
||||
}) extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => IconButton(
|
||||
icon: icon,
|
||||
tooltip: tooltip,
|
||||
onPressed: enabled
|
||||
? () => context.showAdaptiveMenu(itemBuilder(context))
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|||
import "package:file_selector/file_selector.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/widgets/emoji_picker.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter/services.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
|
|
@ -165,10 +167,8 @@ class const Composer(
|
|||
)
|
||||
? [
|
||||
IconButton(
|
||||
onPressed: () => showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => EmojiPicker(
|
||||
onPressed: () => context.showAdaptiveSheet(
|
||||
(context) => EmojiPicker(
|
||||
onSelection: (value) {
|
||||
Navigator.of(context).pop();
|
||||
controller.text += value;
|
||||
|
|
@ -178,7 +178,7 @@ class const Composer(
|
|||
),
|
||||
icon: Icon(Icons.emoji_emotions),
|
||||
),
|
||||
PopupMenuButton(
|
||||
AdaptiveMenuButton(
|
||||
tooltip: "Add media",
|
||||
enabled: attachment == null,
|
||||
itemBuilder: (context) => [
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
|||
import "package:nexus/controllers/init_complete.dart";
|
||||
import "package:nexus/controllers/key.dart";
|
||||
import "package:nexus/controllers/notification_request.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
import "package:nexus/widgets/appbar.dart";
|
||||
import "package:nexus/widgets/sidebar.dart";
|
||||
import "package:nexus/widgets/sync_status_banner.dart";
|
||||
|
|
@ -34,7 +35,7 @@ class const ChatPage({super.key}) extends HookConsumerWidget {
|
|||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isDesktop = constraints.maxWidth > 650;
|
||||
final isDesktop = context.isDesktop;
|
||||
final showMembersByDefault = constraints.maxWidth > 1000;
|
||||
final roomId = ref
|
||||
.watch(KeyController.provider(KeyController.roomKey))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import "package:hooks_riverpod/hooks_riverpod.dart";
|
|||
import "package:nexus/controllers/event.dart";
|
||||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/rooms.dart";
|
||||
import "package:nexus/helpers/extensions/show_context_menu.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_menu.dart";
|
||||
import "package:nexus/helpers/hooks/chat_scroll.dart";
|
||||
import "package:nexus/models/content/avatar.dart";
|
||||
import "package:nexus/models/content/canonical_alias.dart";
|
||||
|
|
@ -197,9 +197,9 @@ class const EventRenderer(
|
|||
|
||||
final contextMenuCallback = getEventOptions == null
|
||||
? null
|
||||
: (PositionedGestureDetails details) => context.showContextMenu(
|
||||
: (PositionedGestureDetails details) => context.showAdaptiveMenu(
|
||||
getEventOptions!(event).toList(),
|
||||
globalPosition: details.globalPosition,
|
||||
children: getEventOptions!(event).toList(),
|
||||
);
|
||||
|
||||
return Column(
|
||||
|
|
@ -222,9 +222,9 @@ class const EventRenderer(
|
|||
final topLeft = renderBox.localToGlobal(
|
||||
Offset.zero,
|
||||
);
|
||||
context.showContextMenu(
|
||||
context.showAdaptiveMenu(
|
||||
getEventOptions!(event).toList(),
|
||||
globalPosition: topLeft,
|
||||
children: getEventOptions!(event).toList(),
|
||||
);
|
||||
return null;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import "package:material_ui/material_ui.dart";
|
|||
import "package:navigation_rail_m3e/navigation_rail_m3e.dart";
|
||||
import "package:nexus/helpers/extensions/get_all_child_rooms.dart";
|
||||
import "package:nexus/helpers/extensions/room_destinations.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:nexus/models/nav_page.dart";
|
||||
import "package:nexus/widgets/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/divider_widget.dart";
|
||||
|
|
@ -149,7 +150,8 @@ class const SpacesRail({super.key}) extends ConsumerWidget {
|
|||
padding: .only(top: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
PopupMenuButton(
|
||||
AdaptiveMenuButton(
|
||||
tooltip: "Add a room",
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => showDialog(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import "package:material_ui/material_ui.dart";
|
|||
import "package:flutter/services.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/widgets/adaptive_menu_button.dart";
|
||||
import "package:nexus/controllers/via.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
|
|
@ -18,7 +19,9 @@ final class const RoomMenuButton(
|
|||
final danger = Theme.of(context).colorScheme.error;
|
||||
final client = ref.read(ClientController.provider.notifier);
|
||||
|
||||
return PopupMenuButton(
|
||||
return AdaptiveMenuButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: "Room options",
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () async {
|
||||
|
|
|
|||
Loading…
Reference in a new issue