Unverified Commit b7a92f05 authored by Pieter van Loon's avatar Pieter van Loon Committed by GitHub

Actually consume top padding in bottomsheet if scrollcontrolled (#66257)

parent 60a8b333
...@@ -472,7 +472,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> { ...@@ -472,7 +472,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
// By definition, the bottom sheet is aligned to the bottom of the page // By definition, the bottom sheet is aligned to the bottom of the page
// and isn't exposed to the top padding of the MediaQuery. // and isn't exposed to the top padding of the MediaQuery.
final Widget bottomSheet = MediaQuery.removePadding( Widget bottomSheet = MediaQuery.removePadding(
context: context, context: context,
removeTop: true, removeTop: true,
child: Builder( child: Builder(
...@@ -490,6 +490,11 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> { ...@@ -490,6 +490,11 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
}, },
), ),
); );
if (isScrollControlled)
bottomSheet = Padding(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: bottomSheet
);
return capturedThemes.wrap(bottomSheet); return capturedThemes.wrap(bottomSheet);
} }
} }
...@@ -572,7 +577,8 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> { ...@@ -572,7 +577,8 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
/// a bottom sheet that will utilize [DraggableScrollableSheet]. If you wish /// a bottom sheet that will utilize [DraggableScrollableSheet]. If you wish
/// to have a bottom sheet that has a scrollable child such as a [ListView] or /// to have a bottom sheet that has a scrollable child such as a [ListView] or
/// a [GridView] and have the bottom sheet be draggable, you should set this /// a [GridView] and have the bottom sheet be draggable, you should set this
/// parameter to true. /// parameter to true. When this parameter is set to true the top of [BottomSheet] will be padded
/// such that it avoids any system top padding given by the [MediaQuery]
/// ///
/// The `useRootNavigator` parameter ensures that the root navigator is used to /// The `useRootNavigator` parameter ensures that the root navigator is used to
/// display the [BottomSheet] when set to `true`. This is useful in the case /// display the [BottomSheet] when set to `true`. This is useful in the case
......
...@@ -425,7 +425,7 @@ void main() { ...@@ -425,7 +425,7 @@ void main() {
expect(find.text('BottomSheet'), findsNothing); expect(find.text('BottomSheet'), findsNothing);
}); });
testWidgets('modal BottomSheet has no top MediaQuery', (WidgetTester tester) async { testWidgets('modal BottomSheet has no top MediaQuery when not scroll controlled', (WidgetTester tester) async {
late BuildContext outerContext; late BuildContext outerContext;
late BuildContext innerContext; late BuildContext innerContext;
...@@ -476,6 +476,60 @@ void main() { ...@@ -476,6 +476,60 @@ void main() {
); );
}); });
testWidgets('modal BottomSheet consumes top MediaQuery when scroll controlled', (WidgetTester tester) async {
late BuildContext outerContext;
late BuildContext innerContext;
final Key containerKey = UniqueKey();
await tester.pumpWidget(Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.all(50.0),
size: Size(400.0, 600.0),
),
child: Navigator(
onGenerateRoute: (_) {
return PageRouteBuilder<void>(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
outerContext = context;
return Container();
},
);
},
),
),
),
));
showModalBottomSheet<void>(
context: outerContext,
isScrollControlled: true,
builder: (BuildContext context) {
innerContext = context;
return Container(key: containerKey);
},
);
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),
);
expect(tester.getTopLeft(find.byKey(containerKey)), const Offset(0.0, 50.0));
});
testWidgets('modal BottomSheet has semantics', (WidgetTester tester) async { testWidgets('modal BottomSheet has semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
......
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