extract adaptive sheets into their own library material_adaptive_sheets
This commit is contained in:
parent
2580cc8c1c
commit
b4d5a632dd
10 changed files with 59 additions and 309 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/widgets/sheet_layout.dart";
|
||||
import "package:flutter/services.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/controllers/pinned_ids.dart";
|
||||
import "package:nexus/controllers/power_level.dart";
|
||||
|
|
@ -12,8 +12,6 @@ import "package:nexus/controllers/rooms.dart";
|
|||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/via.dart";
|
||||
import "package:nexus/helpers/extensions/event_id_is_fake.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/models/content/message.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/models/relation_type.dart";
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension GlobalRect on BuildContext {
|
||||
/// Where the widget this context belongs to is on screen, e.g. to open a
|
||||
/// menu or popover next to it.
|
||||
Rect get globalRect {
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
|
||||
return switch (findRenderObject()) {
|
||||
final RenderBox box =>
|
||||
box.localToGlobal(.zero, ancestor: overlay) & box.size,
|
||||
_ => Rect.zero,
|
||||
};
|
||||
}
|
||||
|
||||
/// [position] on screen as an empty rect, like where text was tapped, to
|
||||
/// open a popover there.
|
||||
Rect globalRectAt(Offset position) {
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
|
||||
return overlay.globalToLocal(position) & .zero;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension IsDesktop on BuildContext {
|
||||
/// Whether the window is wide enough for the desktop layout, with the
|
||||
/// sidebar always visible, menus instead of bottom sheets, etc.
|
||||
bool get isDesktop => MediaQuery.sizeOf(this).width > 650;
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/event.dart";
|
||||
import "package:nexus/controllers/room_summary.dart";
|
||||
import "package:nexus/helpers/extensions/focus_room.dart";
|
||||
import "package:nexus/helpers/extensions/get_link_info.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/helpers/extensions/show_user_popover.dart";
|
||||
import "package:nexus/models/room_summary.dart";
|
||||
import "package:nexus/widgets/room_summary_sheet.dart";
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/widgets/sheet_layout.dart";
|
||||
import "package:flutter_svg/flutter_svg.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:m3e_card_list/m3e_card_list.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/helpers/launch_helper.dart";
|
||||
import "package:package_info_plus/package_info_plus.dart";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/global_rect.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
|
||||
extension ShowAdaptiveMenu on BuildContext {
|
||||
/// Shows [items] in a popup menu on desktop, or a bottom sheet on mobile.
|
||||
///
|
||||
/// On desktop, the menu opens at [globalPosition] if given (e.g. where the
|
||||
/// user right clicked), or over the widget this context belongs to.
|
||||
Future<void> showAdaptiveMenu(
|
||||
List<PopupMenuEntry> items, {
|
||||
Offset? globalPosition,
|
||||
}) async {
|
||||
if (!isDesktop) {
|
||||
await showModalBottomSheet(
|
||||
context: this,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
builder: (context) => SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const .only(bottom: 8),
|
||||
// PopupMenuItems must be inside something with the menu role
|
||||
child: Semantics(
|
||||
role: .menu,
|
||||
explicitChildNodes: true,
|
||||
child: ListTileTheme.merge(
|
||||
contentPadding: const .symmetric(horizontal: 24),
|
||||
minTileHeight: 48,
|
||||
titleTextStyle: Theme.of(context).textTheme.titleMedium,
|
||||
child: Column(mainAxisSize: .min, children: items),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
|
||||
final anchor = switch (globalPosition) {
|
||||
final position? => position & Size.zero,
|
||||
null => globalRect,
|
||||
};
|
||||
|
||||
await showMenu(
|
||||
context: this,
|
||||
constraints: .loose(.infinite),
|
||||
position: .fromRect(anchor, Offset.zero & overlay.size),
|
||||
items: items,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/global_rect.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/widgets/popover_layout.dart";
|
||||
|
||||
extension ShowAdaptivePopover on BuildContext {
|
||||
/// Shows the widget from [builder] in a popover next to [anchor], or the
|
||||
/// widget this context belongs to, on desktop, or a bottom sheet on mobile.
|
||||
/// Use the context passed to [builder] to close it.
|
||||
Future<void> showAdaptivePopover(WidgetBuilder builder, {Rect? anchor}) {
|
||||
if (!isDesktop) return showAdaptiveSheet(builder);
|
||||
|
||||
final rect = anchor ?? globalRect;
|
||||
|
||||
return showDialog(
|
||||
context: this,
|
||||
barrierColor: Colors.transparent,
|
||||
useSafeArea: false,
|
||||
builder: (context) => CustomSingleChildLayout(
|
||||
delegate: PopoverLayout(rect),
|
||||
child: ConstrainedBox(
|
||||
constraints: const .new(maxWidth: 420, maxHeight: 600),
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
clipBehavior: .antiAlias,
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: .circular(16),
|
||||
child: Builder(builder: builder),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/is_desktop.dart";
|
||||
|
||||
extension ShowAdaptiveSheet on BuildContext {
|
||||
/// Shows the widget from [builder] in a dialog on desktop, or a bottom sheet
|
||||
/// on mobile. Use the context passed to [builder] to close it.
|
||||
Future<T?> showAdaptiveSheet<T>(
|
||||
WidgetBuilder builder, {
|
||||
bool enableDrag = true,
|
||||
}) => isDesktop
|
||||
? showDialog<T>(
|
||||
context: this,
|
||||
builder: (context) => Dialog(
|
||||
clipBehavior: .antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const .new(maxWidth: 450, maxHeight: 600),
|
||||
child: Builder(builder: builder),
|
||||
),
|
||||
),
|
||||
)
|
||||
: showModalBottomSheet<T>(
|
||||
context: this,
|
||||
isScrollControlled: true,
|
||||
enableDrag: enableDrag,
|
||||
constraints: .new(maxHeight: MediaQuery.sizeOf(this).height - 80),
|
||||
builder: (context) => SafeArea(child: builder(context)),
|
||||
);
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_sheet.dart";
|
||||
import "package:nexus/helpers/extensions/with_progress_snackbar.dart";
|
||||
import "package:nexus/widgets/sheet_layout.dart";
|
||||
|
||||
extension ShowLeaveRoomSheet on BuildContext {
|
||||
/// Asks the user to confirm leaving the room, then leaves it.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_adaptive_popover.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/widgets/user_bottom_sheet.dart";
|
||||
|
||||
extension ShowUserPopover on BuildContext {
|
||||
|
|
|
|||
Loading…
Reference in a new issue