mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove unwanted gap between navigation bar and safe area's child (#29943)
Remove the additional top padding from CupertinoPageScaffold's MediaQuery when the navigation bar is opaque (as the padding was already consumed by the navigation bar). Related Issue: #29136
This commit is contained in:
parent
393521defe
commit
673e989230
@ -34,7 +34,8 @@ class CupertinoPageScaffold extends StatelessWidget {
|
||||
/// If translucent, the main content may slide behind it.
|
||||
/// Otherwise, the main content's top margin will be offset by its height.
|
||||
///
|
||||
/// The scaffold assumes the navigation bar will consume the [MediaQuery] top padding.
|
||||
/// The scaffold assumes the navigation bar will account for the [MediaQuery] top padding,
|
||||
/// also consume it if the navigation bar is opaque.
|
||||
// TODO(xster): document its page transition animation when ready
|
||||
final ObstructingPreferredSizeWidget navigationBar;
|
||||
|
||||
@ -92,7 +93,10 @@ class CupertinoPageScaffold extends StatelessWidget {
|
||||
// obstructed area.
|
||||
if (fullObstruction) {
|
||||
paddedContent = MediaQuery(
|
||||
data: existingMediaQuery.copyWith(
|
||||
data: existingMediaQuery
|
||||
// If the navigation bar is opaque, the top media query padding is fully consumed by the navigation bar.
|
||||
.removePadding(removeTop: true)
|
||||
.copyWith(
|
||||
viewInsets: newViewInsets,
|
||||
),
|
||||
child: Padding(
|
||||
|
||||
@ -25,6 +25,34 @@ void main() {
|
||||
expect(tester.getTopLeft(find.byType(Center)), const Offset(0.0, 0.0));
|
||||
});
|
||||
|
||||
testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
|
||||
BuildContext childContext;
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(viewInsets: EdgeInsets.only(top: 20)),
|
||||
child: CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('Opaque'),
|
||||
backgroundColor: Color(0xFFF8F8F8),
|
||||
),
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
childContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(MediaQuery.of(childContext).padding.top, 0);
|
||||
// The top of the [Container] is 44 px from the top of the screen because
|
||||
// it's pushed down by the opaque navigation bar whose height is 44 px,
|
||||
// and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar.
|
||||
expect(tester.getRect(find.byType(Container)), Rect.fromLTRB(0, 44, 800, 600));
|
||||
});
|
||||
|
||||
testWidgets('Contents padding from viewInsets', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user