-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add padding for Navigation Bar to account for safe area #102419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set removeLeft and removeRight here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that padding is getting consumed above, so it should be removed for ancestors as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra whitespace here.
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove underscore for local functions.
| expect(rightPaddedCenter.dx, closeTo((defaultWidth - safeAreaPadding) / 2, | ||
| precisionErrorTolerance)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't need the extra ','.
| expect( | ||
| leftPaddedCenter.dx, | ||
| closeTo( | ||
| (defaultWidth + safeAreaPadding) / 2.0, | ||
| precisionErrorTolerance | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
darrenaustin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
@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.