Open a choice menu over its anchor when the anchor is a whole pane
The add-pane picker is opened from a pane, not a button; with no room above or below the anchor the panel was laid out with no height (found by run 303's UI review).
This commit is contained in:
@@ -20,6 +20,8 @@ bool usesDesktopPopups(BuildContext context) {
|
|||||||
///
|
///
|
||||||
/// On a wide app it is a menu panel anchored to [anchor] (the button that
|
/// On a wide app it is a menu panel anchored to [anchor] (the button that
|
||||||
/// opened it): below it, or above when there is no room, kept inside the app.
|
/// opened it): below it, or above when there is no room, kept inside the app.
|
||||||
|
/// When [anchor] is a region rather than a button (a pane), the panel opens
|
||||||
|
/// over its top left.
|
||||||
/// On a phone it is a bottom sheet. Either way it is on the root navigator,
|
/// On a phone it is a bottom sheet. Either way it is on the root navigator,
|
||||||
/// so it is above every floating window. Escape, Back or a press outside
|
/// so it is above every floating window. Escape, Back or a press outside
|
||||||
/// closes it; the content closes it with `Navigator.of(context).pop(value)`.
|
/// closes it; the content closes it with `Navigator.of(context).pop(value)`.
|
||||||
@@ -169,38 +171,59 @@ class _AnchoredMenuLayout extends SingleChildLayoutDelegate {
|
|||||||
static const double margin = 8;
|
static const double margin = 8;
|
||||||
static const double gap = 4;
|
static const double gap = 4;
|
||||||
|
|
||||||
|
/// Less room than this on both sides means the anchor is not a button but
|
||||||
|
/// a region (a pane's bar, a whole pane): the panel then opens over it,
|
||||||
|
/// from its top.
|
||||||
|
static const double minRoom = 200;
|
||||||
|
|
||||||
|
double _below(Size size) => size.height - anchor.bottom - gap - margin;
|
||||||
|
double _above() => anchor.top - gap - margin;
|
||||||
|
bool _over(Size size) => _below(size) < minRoom && _above() < minRoom;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
|
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
|
||||||
final available = constraints.biggest;
|
final available = constraints.biggest;
|
||||||
final below = available.height - anchor.bottom - gap - margin;
|
final below = _below(available);
|
||||||
final above = anchor.top - gap - margin;
|
final above = _above();
|
||||||
final height = (below >= 240 || below >= above ? below : above).clamp(
|
final double room;
|
||||||
0.0,
|
if (_over(available)) {
|
||||||
available.height - 2 * margin,
|
room =
|
||||||
);
|
available.height -
|
||||||
|
anchor.top.clamp(margin, available.height) -
|
||||||
|
margin;
|
||||||
|
} else {
|
||||||
|
room = below >= minRoom || below >= above ? below : above;
|
||||||
|
}
|
||||||
final maxWidth = (available.width - 2 * margin).clamp(0.0, double.infinity);
|
final maxWidth = (available.width - 2 * margin).clamp(0.0, double.infinity);
|
||||||
return BoxConstraints(
|
return BoxConstraints(
|
||||||
minWidth: width.clamp(0.0, maxWidth),
|
minWidth: width.clamp(0.0, maxWidth),
|
||||||
maxWidth: width.clamp(0.0, maxWidth),
|
maxWidth: width.clamp(0.0, maxWidth),
|
||||||
maxHeight: height,
|
maxHeight: room.clamp(0.0, available.height - 2 * margin),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Offset getPositionForChild(Size size, Size childSize) {
|
Offset getPositionForChild(Size size, Size childSize) {
|
||||||
final below = size.height - anchor.bottom - gap - margin;
|
final double top;
|
||||||
final fitsBelow = childSize.height <= below;
|
if (_over(size)) {
|
||||||
final top = fitsBelow
|
top = anchor.top + gap;
|
||||||
? anchor.bottom + gap
|
} else if (childSize.height <= _below(size)) {
|
||||||
: (anchor.top - gap - childSize.height).clamp(
|
top = anchor.bottom + gap;
|
||||||
margin,
|
} else {
|
||||||
size.height - margin - childSize.height,
|
top = anchor.top - gap - childSize.height;
|
||||||
);
|
}
|
||||||
final left = anchor.left.clamp(
|
final maxTop = (size.height - margin - childSize.height).clamp(
|
||||||
margin,
|
margin,
|
||||||
(size.width - margin - childSize.width).clamp(margin, double.infinity),
|
double.infinity,
|
||||||
|
);
|
||||||
|
final maxLeft = (size.width - margin - childSize.width).clamp(
|
||||||
|
margin,
|
||||||
|
double.infinity,
|
||||||
|
);
|
||||||
|
return Offset(
|
||||||
|
anchor.left.clamp(margin, maxLeft),
|
||||||
|
top.clamp(margin, maxTop),
|
||||||
);
|
);
|
||||||
return Offset(left, top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -102,6 +102,42 @@ void main() {
|
|||||||
expect(menu.top, greaterThanOrEqualTo(8));
|
expect(menu.top, greaterThanOrEqualTo(8));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('wide: anchored to a whole pane, the menu opens over its top', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
_size(tester, const Size(1280, 800));
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 400),
|
||||||
|
child: Builder(
|
||||||
|
builder: (pane) => Center(
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () => showAppChoiceMenu<void>(
|
||||||
|
pane,
|
||||||
|
width: 420,
|
||||||
|
builder: (_) => const SizedBox(
|
||||||
|
height: 300,
|
||||||
|
child: Center(child: Text('Picker')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text('Open'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('Open'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final menu = tester.getRect(_menu);
|
||||||
|
expect(menu.size.width, 420);
|
||||||
|
expect(menu.height, greaterThanOrEqualTo(300));
|
||||||
|
expect(menu.left, 400);
|
||||||
|
expect(menu.top, lessThan(40));
|
||||||
|
expect(find.text('Picker').hitTestable(), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('wide: details are a dialog', (tester) async {
|
testWidgets('wide: details are a dialog', (tester) async {
|
||||||
_size(tester, const Size(1280, 800));
|
_size(tester, const Size(1280, 800));
|
||||||
await tester.pumpWidget(_app());
|
await tester.pumpWidget(_app());
|
||||||
|
|||||||
Reference in New Issue
Block a user