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

This commit is contained in:
xster
2017-12-12 11:25:20 -08:00
committed by GitHub
parent 715916fe1b
commit e2192a90fc
3 changed files with 66 additions and 13 deletions

View File

@@ -234,7 +234,13 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
@override
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)
bottomSheet = new Theme(data: theme, child: bottomSheet);
return bottomSheet;

View File

@@ -231,27 +231,30 @@ void main() {
});
testWidgets('Dialogs removes MediaQuery padding', (WidgetTester tester) async {
BuildContext scaffoldContext;
BuildContext outerContext;
BuildContext dialogContext;
await tester.pumpWidget(new MaterialApp(
home: new MediaQuery(
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.all(50.0),
),
child: new Builder(
builder: (BuildContext context) {
scaffoldContext = context;
return new Container();
}
child: new Navigator(
onGenerateRoute: (_) {
return new PageRouteBuilder<Null>(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
outerContext = context;
return new Container();
},
);
},
),
)
),
));
await tester.pump();
showDialog<Null>(
context: scaffoldContext,
context: outerContext,
barrierDismissible: false,
child: new Builder(
builder: (BuildContext context) {
@@ -263,6 +266,7 @@ void main() {
await tester.pump();
expect(MediaQuery.of(outerContext).padding, const EdgeInsets.all(50.0));
expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero);
});
}

View File

@@ -153,4 +153,47 @@ void main() {
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),
);
});
}