Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Apr 18, 2022

Description

  • Add a check in Scaffold.performLayout to throw a Flutter error when a SnackBar is off screen.
  • Update Scaffold.showSnackBar troubleshooting comments.
  • Add an example.

Related Issue

Fixes #84263

Tests

Add a test to material/snack_bar_test.dart
Add a test for the new example

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.

@bleroux bleroux requested a review from Piinks April 18, 2022 11:45
@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Apr 18, 2022
@Piinks Piinks added the a: error message Error messages from the Flutter framework label Apr 19, 2022
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

This is a really helpful addition to the API - thank you! Just a few suggestions and nits

@bleroux bleroux requested a review from Piinks April 19, 2022 21:20
@bleroux bleroux force-pushed the floating_snackbar_troubleshooting branch from c596435 to 6ded7c3 Compare April 26, 2022 13:59
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! The example and the example's tests look great. It looks like there are more cases though that can cause this issue that we should be catching, see notes below. :)

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement already exists above on line 1092, can this just be included in that block?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps not, since the position of a floating snackbar can be affected by other Scaffold widgets too, like persistent footer buttons and bottom navigation bars, can you account for these cases too?

Suggested change
if (floatingActionButtonRect.size != Size.zero && isSnackBarFloating) {
if ( isSnackBarFloating) {

Maybe? If there is no floating action button, how are the other cases handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Piinks
Very interesting! Large persistent footer buttons and large bottom navigation bars might happen too. I updated the PR accordingly.
About the if statement location, the check has to be done after calling positionChild otherwise the error is thrown before position is calculated and the SnackBar position will differ in debug mode (I first put the message in the existing if statement and noticed that).

Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement already exists above on line 1092, can this just be included in that block?

@bleroux bleroux force-pushed the floating_snackbar_troubleshooting branch 2 times, most recently from 0fce53d to 34be384 Compare April 28, 2022 09:56
@bleroux bleroux requested a review from Piinks April 28, 2022 12:19
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I follow this comment, why do we have to wait until after calling positionChild? We have the information we need to assert prior to the call right?

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 @Piinks!
If the assert is done before calling positionChild, the error is thrown and the Snackbar is positionned at (0,0).
Here is a screenshot :
Capture d’écran du 2022-05-12 10-31-59

If the assert is done after positionChild, the error is thrown and the SnackBar is not visible :
Capture d’écran du 2022-05-12 10-31-23

As we are throwing an error saying the SnackBar is not visible, It might feels strange for the user to see the Snackbar in this case. Maybe my comment could be reworded?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it does seem to be a contradiction - why would it throw in the case of the first image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed an update where I tried to make the comment clearer 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately the commit history was squashed so I cannot see what specifically changed.

why would it throw in the case of the first image?

I am still wondering this. :)

@bleroux bleroux force-pushed the floating_snackbar_troubleshooting branch 3 times, most recently from de39b02 to c14f96e Compare May 13, 2022 08:37
@bleroux bleroux requested a review from Piinks May 13, 2022 09:14
Copy link
Contributor

Choose a reason for hiding this comment

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

the error message states that the SnackBar is off screen.

Why would this error message be presented if it is on screen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the error message states that the SnackBar is off screen.

Why would this error message be presented if it is on screen?

This comment is about what would happen if we assert earlier, in the following if statement
https://github.com/flutter/flutter/blob/c14f96ed81c096fdde6d4bdb8d77c5ccbaac06e4/packages/flutter/lib/src/material/scaffold.dart#L1107

If we do the assert in this if statement, the error message will rightly state that the SnackBar is off screen, but the SnackBar will be wrongly visible at (0,0). The reason is that, before calling positionChild, the SnackBar has a default position of (0,0).
If the assert is done before calling positionChild, the final position will not be updated and the SnackBar will be wrongly visible (in debug mode).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for explaining! I had a hard time wrapping my head around this one. :)

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM!

@bleroux bleroux force-pushed the floating_snackbar_troubleshooting branch from c14f96e to 0c745a8 Compare May 26, 2022 09:21
@fluttergithubbot fluttergithubbot merged commit bc53e62 into flutter:master May 26, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: error message Error messages from the Flutter framework c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos 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.

Snackbar with SnackBarBehavior.floating is affected by widgets provided to floatingActionButton parameter in the Scaffold

3 participants