Fix constraints of popupmenu (#75748)

This commit is contained in:
Michael Goderbauer 2021-02-09 17:41:03 -08:00 committed by GitHub
parent 3e89f24233
commit 531870f57b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 3 deletions

View File

@ -623,9 +623,7 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
// The menu can be at most the size of the overlay minus 8.0 pixels in each
// direction.
return BoxConstraints.loose(
constraints.biggest - const Offset(_kMenuScreenPadding * 2.0, _kMenuScreenPadding * 2.0) as Size,
);
return BoxConstraints.loose(constraints.biggest).deflate(const EdgeInsets.all(_kMenuScreenPadding));
}
@override

View File

@ -1915,6 +1915,46 @@ void main() {
await buildFrame(iconSize: 50);
expect(tester.widget<IconButton>(find.byType(IconButton)).iconSize, 50);
});
testWidgets('does not crash in small overlay', (WidgetTester tester) async {
final GlobalKey navigator = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
OutlinedButton(
onPressed: () {
showMenu<void>(
context: navigator.currentContext!,
position: const RelativeRect.fromLTRB(0, 0, 0, 0),
items: const <PopupMenuItem<void>>[
PopupMenuItem<void>(child: Text('foo')),
],
);
},
child: const Text('press'),
),
SizedBox(
height: 10,
width: 10,
child: Navigator(
key: navigator,
onGenerateRoute: (RouteSettings settings) => MaterialPageRoute<void>(
builder: (BuildContext context) => Container(color: Colors.red),
),
),
),
],
),
),
),
);
await tester.tap(find.text('press'));
await tester.pumpAndSettle();
expect(find.text('foo'), findsOneWidget);
});
}
class TestApp extends StatefulWidget {