Unverified Commit 6f773944 authored by xster's avatar xster Committed by GitHub

Remove dangling MediaQuery paddings for non-fullscreen dialogs - 2 (#13438)

* Remove MediaQuery padding for various PopupRoutes that don't extend to the edge of the screen

* bottom sheet doesn't actually need handling. Scaffold does it already. Add test for others.
parent 6ff844a9
......@@ -427,7 +427,18 @@ class _DialogRoute<T> extends PopupRoute<T> {
@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return theme != null ? new Theme(data: theme, child: child) : child;
return new MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
removeLeft: true,
removeRight: true,
child: new Builder(
builder: (BuildContext context) {
return theme != null ? new Theme(data: theme, child: child) : child;
}
),
);
}
@override
......
......@@ -335,14 +335,25 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
if (theme != null)
menu = new Theme(data: theme, child: menu);
return new CustomSingleChildLayout(
delegate: new _DropdownMenuRouteLayout<T>(
buttonRect: buttonRect,
menuTop: menuTop,
menuHeight: menuHeight,
textDirection: Directionality.of(context),
return new MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
removeLeft: true,
removeRight: true,
child: new Builder(
builder: (BuildContext context) {
return new CustomSingleChildLayout(
delegate: new _DropdownMenuRouteLayout<T>(
buttonRect: buttonRect,
menuTop: menuTop,
menuHeight: menuHeight,
textDirection: Directionality.of(context),
),
child: menu,
);
},
),
child: menu,
);
}
......
......@@ -591,17 +591,24 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
if (theme != null)
menu = new Theme(data: theme, child: menu);
return new Builder(
builder: (BuildContext context) {
return new CustomSingleChildLayout(
delegate: new _PopupMenuRouteLayout(
position,
selectedItemOffset,
Directionality.of(context),
),
child: menu,
);
},
return new MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
removeLeft: true,
removeRight: true,
child: new Builder(
builder: (BuildContext context) {
return new CustomSingleChildLayout(
delegate: new _PopupMenuRouteLayout(
position,
selectedItemOffset,
Directionality.of(context),
),
child: menu,
);
},
),
);
}
}
......
......@@ -229,4 +229,40 @@ void main() {
semantics.dispose();
});
testWidgets('Dialogs removes MediaQuery padding', (WidgetTester tester) async {
BuildContext scaffoldContext;
BuildContext dialogContext;
await tester.pumpWidget(new MaterialApp(
home: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.all(50.0),
),
child: new Builder(
builder: (BuildContext context) {
scaffoldContext = context;
return new Container();
}
),
)
));
await tester.pump();
showDialog<Null>(
context: scaffoldContext,
barrierDismissible: false,
child: new Builder(
builder: (BuildContext context) {
dialogContext = context;
return new Container();
},
),
);
await tester.pump();
expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero);
});
}
......@@ -91,4 +91,46 @@ void main() {
expect(buildCount, equals(1));
});
testWidgets('Scaffold removes top MediaQuery padding', (WidgetTester tester) async {
BuildContext scaffoldContext;
BuildContext bottomSheetContext;
await tester.pumpWidget(new MaterialApp(
home: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.all(50.0),
),
child: new Scaffold(
resizeToAvoidBottomPadding: false,
body: new Builder(
builder: (BuildContext context) {
scaffoldContext = context;
return new Container();
}
),
),
)
));
await tester.pump();
showBottomSheet<Null>(
context: scaffoldContext,
builder: (BuildContext context) {
bottomSheetContext = context;
return new Container();
},
);
await tester.pump();
expect(
MediaQuery.of(bottomSheetContext).padding,
const EdgeInsets.only(
bottom: 50.0,
left: 50.0,
right: 50.0,
),
);
});
}
......@@ -315,6 +315,47 @@ void main() {
await testPositioningDownThenUp(tester, TextDirection.ltr, Alignment.bottomCenter, TextDirection.ltr, new Rect.fromLTWH(350.0, 500.0, 0.0, 0.0));
await testPositioningDownThenUp(tester, TextDirection.rtl, Alignment.bottomCenter, TextDirection.rtl, new Rect.fromLTWH(450.0, 500.0, 0.0, 0.0));
});
testWidgets('PopupMenu removes MediaQuery padding', (WidgetTester tester) async {
BuildContext popupContext;
await tester.pumpWidget(new MaterialApp(
home: new MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.all(50.0),
),
child: new Material(
child: new PopupMenuButton<int>(
itemBuilder: (BuildContext context) {
popupContext = context;
return <PopupMenuItem<int>>[
new PopupMenuItem<int>(
value: 1,
child: new Builder(
builder: (BuildContext context) {
popupContext = context;
return const Text('AAA');
},
),
),
];
},
child: const SizedBox(
height: 100.0,
width: 100.0,
child: const Text('XXX'),
),
),
),
)
));
await tester.tap(find.text('XXX'));
await tester.pump();
expect(MediaQuery.of(popupContext).padding, EdgeInsets.zero);
});
}
class TestApp extends StatefulWidget {
......
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