Skip to content

Conversation

@QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Apr 23, 2022

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.
Screen Shot 2022-04-22 at 5 53 48 PM
Screen Shot 2022-04-22 at 5 55 24 PM
Screen Shot 2022-04-22 at 5 56 15 PM

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 23, 2022
@QuncCccccc QuncCccccc force-pushed the bugfix/navigationBar-doesnt-account-for-safe-area branch from 21ddb1c to 1489931 Compare April 23, 2022 01:08
@QuncCccccc QuncCccccc requested a review from Piinks April 23, 2022 01:09
@QuncCccccc QuncCccccc marked this pull request as ready for review April 23, 2022 01:10
additionalRightPadding, additionalBottomPadding),
child: MediaQuery.removePadding(
context: context,
removeBottom: true,
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

@QuncCccccc QuncCccccc Apr 25, 2022

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,
Copy link
Member

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));
});


Copy link
Member

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.

@QuncCccccc QuncCccccc requested a review from darrenaustin April 26, 2022 16:01
Copy link
Member

@goderbauer goderbauer left a 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() {
Copy link
Member

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.

Comment on lines 200 to 201
expect(rightPaddedCenter.dx, closeTo((defaultWidth - safeAreaPadding) / 2,
precisionErrorTolerance));
Copy link
Member

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:

Suggested change
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.

Comment on lines 206 to 207
data: const MediaQueryData(padding: EdgeInsets.fromLTRB(
safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)),
Copy link
Member

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.

Suggested change
data: const MediaQueryData(padding: EdgeInsets.fromLTRB(
safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)),
data: const MediaQueryData(
padding: EdgeInsets.fromLTRB(
safeAreaPadding, 0, safeAreaPadding, safeAreaPadding,
),
),

Comment on lines 206 to 207
data: const MediaQueryData(padding: EdgeInsets.fromLTRB(
safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer:

Suggested change
data: const MediaQueryData(padding: EdgeInsets.fromLTRB(
safeAreaPadding, 0, safeAreaPadding, safeAreaPadding)),
data: const MediaQueryData(
padding: EdgeInsets.fromLTRB(
safeAreaPadding,
0,
safeAreaPadding,
safeAreaPadding,
),
),

Copy link
Contributor

@darrenaustin darrenaustin left a 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.

Comment on lines -157 to -161
child: Padding(
padding: EdgeInsets.only(bottom: additionalBottomPadding),
child: MediaQuery.removePadding(
context: context,
removeBottom: true,
Copy link
Contributor

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.

Copy link
Contributor Author

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:)

Copy link
Contributor

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(),));
Copy link
Contributor

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 ','.

Comment on lines 186 to 191
expect(
leftPaddedCenter.dx,
closeTo(
(defaultWidth + safeAreaPadding) / 2.0,
precisionErrorTolerance
),
Copy link
Contributor

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?

Copy link
Contributor

@darrenaustin darrenaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Moncader
Copy link

@QuncCccccc @darrenaustin
This PR has made a degradation in Flutter 3.3 where if you have an app that doesn't use a widget consuming the MediaQuery's top padding (like AppBar does), the top padding of the safe area (the notification shade area) gets added to the top of the NavigationBar making the bar very tall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NavigationBar doesn't account for safe area

6 participants