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
33
lib/widgets/popover_layout.dart
Normal file
33
lib/widgets/popover_layout.dart
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import "dart:math";
|
||||
|
||||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
/// Positions a popover below [anchor], or above it if there isn't room below,
|
||||
/// keeping it fully on screen.
|
||||
class const PopoverLayout(final Rect anchor) extends SingleChildLayoutDelegate {
|
||||
static const margin = 8.0;
|
||||
|
||||
@override
|
||||
BoxConstraints getConstraintsForChild(BoxConstraints constraints) =>
|
||||
constraints.loosen().deflate(const .all(margin));
|
||||
|
||||
@override
|
||||
Offset getPositionForChild(Size size, Size childSize) {
|
||||
final fitsBelow = anchor.bottom + childSize.height + margin <= size.height;
|
||||
|
||||
return .new(
|
||||
anchor.left.clamp(
|
||||
margin,
|
||||
max(margin, size.width - childSize.width - margin),
|
||||
),
|
||||
(fitsBelow ? anchor.bottom : anchor.top - childSize.height).clamp(
|
||||
margin,
|
||||
max(margin, size.height - childSize.height - margin),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRelayout(PopoverLayout oldDelegate) =>
|
||||
oldDelegate.anchor != anchor;
|
||||
}
|
||||
Loading…
Reference in a new issue