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.
This commit is contained in:
parent
6ff844a9c0
commit
6f773944ae
@ -427,8 +427,19 @@ class _DialogRoute<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) {
|
||||||
|
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;
|
return theme != null ? new Theme(data: theme, child: child) : child;
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
||||||
|
@ -335,6 +335,14 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
|
|||||||
if (theme != null)
|
if (theme != null)
|
||||||
menu = new Theme(data: theme, child: menu);
|
menu = new Theme(data: theme, 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(
|
return new CustomSingleChildLayout(
|
||||||
delegate: new _DropdownMenuRouteLayout<T>(
|
delegate: new _DropdownMenuRouteLayout<T>(
|
||||||
buttonRect: buttonRect,
|
buttonRect: buttonRect,
|
||||||
@ -344,6 +352,9 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
|
|||||||
),
|
),
|
||||||
child: menu,
|
child: menu,
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _dismiss() {
|
void _dismiss() {
|
||||||
|
@ -591,7 +591,13 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||||||
if (theme != null)
|
if (theme != null)
|
||||||
menu = new Theme(data: theme, child: menu);
|
menu = new Theme(data: theme, child: menu);
|
||||||
|
|
||||||
return new Builder(
|
return new MediaQuery.removePadding(
|
||||||
|
context: context,
|
||||||
|
removeTop: true,
|
||||||
|
removeBottom: true,
|
||||||
|
removeLeft: true,
|
||||||
|
removeRight: true,
|
||||||
|
child: new Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return new CustomSingleChildLayout(
|
return new CustomSingleChildLayout(
|
||||||
delegate: new _PopupMenuRouteLayout(
|
delegate: new _PopupMenuRouteLayout(
|
||||||
@ -602,6 +608,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||||||
child: menu,
|
child: menu,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,4 +229,40 @@ void main() {
|
|||||||
|
|
||||||
semantics.dispose();
|
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));
|
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.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));
|
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 {
|
class TestApp extends StatefulWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user