forked from Nexus/nexus
make user sheets popovers on desktop
This commit is contained in:
parent
76d78596cd
commit
ce5c7b972b
6 changed files with 122 additions and 44 deletions
35
lib/helpers/extensions/show_adaptive_popover.dart
Normal file
35
lib/helpers/extensions/show_adaptive_popover.dart
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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 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) {
|
||||
if (!isDesktop) return showAdaptiveSheet(builder);
|
||||
|
||||
final anchor = globalRect;
|
||||
|
||||
return showDialog(
|
||||
context: this,
|
||||
barrierColor: Colors.transparent,
|
||||
useSafeArea: false,
|
||||
builder: (context) => CustomSingleChildLayout(
|
||||
delegate: PopoverLayout(anchor),
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue