Unverified Commit e2192a90 authored by xster's avatar xster Committed by GitHub

Remove top mediaquery padding from modal bottom sheets (#13497)

parent 715916fe
...@@ -234,7 +234,13 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> { ...@@ -234,7 +234,13 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
@override @override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
Widget bottomSheet = new _ModalBottomSheet<T>(route: this); // By definition, the bottom sheet is aligned to the bottom of the page
// and isn't exposed to the top padding of the MediaQuery.
Widget bottomSheet = new MediaQuery.removePadding(
context: context,
removeTop: true,
child: new _ModalBottomSheet<T>(route: this),
);
if (theme != null) if (theme != null)
bottomSheet = new Theme(data: theme, child: bottomSheet); bottomSheet = new Theme(data: theme, child: bottomSheet);
return bottomSheet; return bottomSheet;
......
...@@ -231,27 +231,30 @@ void main() { ...@@ -231,27 +231,30 @@ void main() {
}); });
testWidgets('Dialogs removes MediaQuery padding', (WidgetTester tester) async { testWidgets('Dialogs removes MediaQuery padding', (WidgetTester tester) async {
BuildContext scaffoldContext; BuildContext outerContext;
BuildContext dialogContext; BuildContext dialogContext;
await tester.pumpWidget(new MaterialApp( await tester.pumpWidget(new Directionality(
home: new MediaQuery( textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: const EdgeInsets.all(50.0), padding: const EdgeInsets.all(50.0),
), ),
child: new Builder( child: new Navigator(
builder: (BuildContext context) { onGenerateRoute: (_) {
scaffoldContext = context; return new PageRouteBuilder<Null>(
return new Container(); pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
} outerContext = context;
return new Container();
},
);
},
), ),
) ),
)); ));
await tester.pump();
showDialog<Null>( showDialog<Null>(
context: scaffoldContext, context: outerContext,
barrierDismissible: false, barrierDismissible: false,
child: new Builder( child: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -263,6 +266,7 @@ void main() { ...@@ -263,6 +266,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(MediaQuery.of(outerContext).padding, const EdgeInsets.all(50.0));
expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero); expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero);
}); });
} }
...@@ -153,4 +153,47 @@ void main() { ...@@ -153,4 +153,47 @@ void main() {
expect(find.text('BottomSheet'), findsNothing); expect(find.text('BottomSheet'), findsNothing);
}); });
testWidgets('modal BottomSheet has no top MediaQuery', (WidgetTester tester) async {
BuildContext outerContext;
BuildContext innerContext;
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.all(50.0),
),
child: new Navigator(
onGenerateRoute: (_) {
return new PageRouteBuilder<Null>(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
outerContext = context;
return new Container();
},
);
},
),
),
));
showModalBottomSheet<Null>(
context: outerContext,
builder: (BuildContext context) {
innerContext = context;
return new Container();
},
);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(
MediaQuery.of(outerContext).padding,
const EdgeInsets.all(50.0),
);
expect(
MediaQuery.of(innerContext).padding,
const EdgeInsets.only(left: 50.0, right: 50.0, bottom: 50.0),
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment