Add padding for Navigation Bar to account for safe area#102419
Conversation
21ddb1c to
1489931
Compare
| additionalRightPadding, additionalBottomPadding), | ||
| child: MediaQuery.removePadding( | ||
| context: context, | ||
| removeBottom: true, |
There was a problem hiding this comment.
Should we set removeLeft and removeRight here?
There was a problem hiding this comment.
Looks like that padding is getting consumed above, so it should be removed for ancestors as suggested.
There was a problem hiding this comment.
Thanks for the comments! Looks like SafeArea does same thing just like what Padding() and MediaQuery.removePadding() do, so I removed both and use SafeArea instead. Let me know if you have any suggestions.
https://github.com/flutter/flutter/blob/5464c5bac7/packages/flutter/lib/src/widgets/safe_area.dart#:~:text=return%20Padding(,child%3A%20MediaQuery.removePadding(
| additionalRightPadding, additionalBottomPadding), | ||
| child: MediaQuery.removePadding( | ||
| context: context, | ||
| removeBottom: true, |
There was a problem hiding this comment.
Looks like that padding is getting consumed above, so it should be removed for ancestors as suggested.
| expect(paddedCenter.dx, closeTo(defaultWidth / 2, precisionErrorTolerance)); | ||
| }); | ||
|
|
||
|
|
There was a problem hiding this comment.
nit: remove extra whitespace here.
goderbauer
left a comment
There was a problem hiding this comment.
LGTM with some formatting nits
|
|
||
| testWidgets('NavigationBar respects the notch/system navigation bar in landscape mode', (WidgetTester tester) async { | ||
| const double safeAreaPadding = 40.0; | ||
| Widget _navigationBar() { |
There was a problem hiding this comment.
nit: remove underscore for local functions.
| expect(rightPaddedCenter.dx, closeTo((defaultWidth - safeAreaPadding) / 2, | ||
| precisionErrorTolerance)); |
There was a problem hiding this comment.
format nit to make this easier to read:
| expect(rightPaddedCenter.dx, closeTo((defaultWidth - safeAreaPadding) / 2, | |
| precisionErrorTolerance)); | |
| expect( | |
| rightPaddedCenter.dx, | |
| closeTo((defaultWidth - safeAreaPadding) / 2, precisionErrorTolerance), | |
| ); |
Basically, the line with the opening and closing parenthesis should always have the same indentation.
| data: const MediaQueryData(padding: EdgeInsets.fromLTRB( | ||
| safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)), |
There was a problem hiding this comment.
format nit: properties of a widget should be on their own line, e.g.
| data: const MediaQueryData(padding: EdgeInsets.fromLTRB( | |
| safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)), | |
| data: const MediaQueryData( | |
| padding: EdgeInsets.fromLTRB( | |
| safeAreaPadding, 0, safeAreaPadding, safeAreaPadding, | |
| ), | |
| ), |
| data: const MediaQueryData(padding: EdgeInsets.fromLTRB( | ||
| safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)), |
There was a problem hiding this comment.
I would prefer:
| data: const MediaQueryData(padding: EdgeInsets.fromLTRB( | |
| safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)), | |
| data: const MediaQueryData( | |
| padding: EdgeInsets.fromLTRB( | |
| safeAreaPadding, | |
| 0, | |
| safeAreaPadding, | |
| safeAreaPadding, | |
| ), | |
| ), |
darrenaustin
left a comment
There was a problem hiding this comment.
Looks good. Just a question and a couple of nits below.
| child: Padding( | ||
| padding: EdgeInsets.only(bottom: additionalBottomPadding), | ||
| child: MediaQuery.removePadding( | ||
| context: context, | ||
| removeBottom: true, |
There was a problem hiding this comment.
Do we know what this padding and MediaQuery were doing here? It looks like they were doing something specific with bottom padding that has been removed in this PR.
There was a problem hiding this comment.
Based on my understanding, the Padding(...MediaQuery.removePadding(...)) part is just giving a SafeArea for device bottom. The code does same thing just like what SafeArea api does, so when I want to add additionalLeftPadding and additionalRightPadding, I replaced all of them with SafeArea. Please let me know if it makes sense to you:)
There was a problem hiding this comment.
It does. Just wanted to make sure we knew why it was ok to remove this. Thx.
| ); | ||
| } | ||
|
|
||
| await tester.pumpWidget(_buildWidget(navigationBar(),)); |
There was a problem hiding this comment.
Nit: don't need the extra ','.
| expect( | ||
| leftPaddedCenter.dx, | ||
| closeTo( | ||
| (defaultWidth + safeAreaPadding) / 2.0, | ||
| precisionErrorTolerance | ||
| ), |
There was a problem hiding this comment.
nit: we usually indent only two spaces for continued lines like this. This applies to all the code below this as well.
In this case it looks like the closeTo call could also be on one line?
|
@QuncCccccc @darrenaustin |
This PR adds paddings for Navigation Bar so that when a Android/iOS device is in landscape mode, the Navigation Bar will respect SafeAreas by default.
Fixes #101605.



Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.