Skip to content

Conversation

@Piinks
Copy link
Contributor

@Piinks Piinks commented Jun 24, 2020

Description

This PR makes Scaffold.floatingActionButtons respect safe areas. This is done by adding minViewPadding to _ScaffoldLayout and the ScaffoldPrelayoutGeometry, so we can check that the button is placed within a valid interactive area.
The FAB usually uses kFloatingActionButtonMargin, or aligns with the relevant objects for the given location, like the BottomNavigationBar, BottomSheet, AppBar, or SnackBar. With viewPadding added into consideration, it will conditionally choose the viewPadding if one of the standard options does not result in a safe position.

Example:

FloatingActionButton.endFloat chooses (bottom: 34.0, right: 16.0) for safe interaction. (34.0 being the bottom viewPadding, and 16.0 the default kFloatingActionButtonMargin.
Screen Shot 2020-06-24 at 12 15 09 PM

FloatingActionButtonLocation.endFloat chooses default kFloatingActionButtonMargin (16.0) for bottom and right as there are no interfering obstructions:
Screen Shot 2020-06-24 at 12 16 09 PM

Related Issues

Fixes #58942
Fixes #30105
b/158392371

Tests

I added the following tests:

Oodles!
There are a lot of tests here since so many Scaffold elements affect the FAB placement, and there are 18 FAB locations. I split them into three main categories, the Float, Top, and End locations.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@Piinks Piinks added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. a: quality A truly polished experience customer: money (g3) labels Jun 24, 2020
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM. The tests are superb!

));
expect(
tester.getRect(find.byKey(floatingActionButton)),
rectMoreOrLessEquals(defaultRect),
Copy link
Contributor

Choose a reason for hiding this comment

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

Whey are we using rectMoreOrlessEquals here and elsewhere? It would be OK to just include an explanatory comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I borrowed a little from other FAB tests. I'm not sure we have to use rectMoreOrLessEquals. I'll see if I can simplify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, just checked. This is required as it accounts for the precisionErrorTolerance. The tests will not pass otherwise.

@flutter-github-sync
Copy link

Started Google testing for this PR

@flutter-github-sync
Copy link

Google testing passed!

@flutter-github-sync
Copy link

Started Google testing for this PR

3 similar comments
@flutter-github-sync
Copy link

Started Google testing for this PR

@flutter-github-sync
Copy link

Started Google testing for this PR

@flutter-github-sync
Copy link

Started Google testing for this PR

@flutter-github-sync
Copy link

Google testing passed!

@flutter-github-sync
Copy link

Started Google testing for this PR

@flutter-github-sync
Copy link

Google testing passed!

@fluttergithubbot fluttergithubbot merged commit fd7a72e into flutter:master Jun 26, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
final bool extendBody;
final bool extendBodyBehindAppBar;
final EdgeInsets minInsets;
final EdgeInsets minViewPadding;
Copy link
Member

Choose a reason for hiding this comment

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

@Piinks Hey, I am currently working on another scaffold issue.
some tests block me. it seems to be relative to this change.
I am wondering why not add minViewPadding to shouldRelayout(oldDelegate), it should re-layout if it changes, right?

If the above is right, this test('Floating Action Button bottom padding not consumed by viewInsets') will fail, could you take a look at this?

Additional, the test was added in #34298 by you too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @xu-baolin! Can you share the issue you are working on? It will help me better understand. It's been a while since I worked on this so I am trying to refresh my memory. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at Floating Action Button bottom padding not consumed by viewInsets, it makes sense to me, but the issue you are working on may provide a reason otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

@Piinks Thanks for the help.
#104954 will give more infomation.

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

Labels

a: quality A truly polished experience customer: money (g3) 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.

Floating action buttons don't respect SafeArea SafeArea should have a fab parameter

6 participants