Skip to content

Conversation

@filaps
Copy link
Contributor

@filaps filaps commented Dec 22, 2019

Description

Screenshots

Before fix

After fix

Bug cause

Scaffold always wraps a FloatingActionButton(FAB) in a private widget _FloatingActionButtonTransition, even if the FAB is null (to animate the appearance of the FAB).
Thus, Scaffold always has a FAB and calculates an area for it. Before calculating the position of the SnackBar, Scaffold verifies the area of FAB on null. If the area is not null, then SnackBar will be positioned above it. Since FAB and its area is never null, SnackBar is always on top (This bug works only for SnackBar with floating behavior)

Solution

If the FAB is null, then FloatingActionButtonArea has a size equal to Size.zero. Consequently, if the size of FloatingActionButtonArea is zero, then FAB won't show and SnackBar will be laid out on top of the other content.

Tests

This PR also adds tests to ensure that the SnackBar is positioned in the right places given the many configurations of Scaffold

Related Issues

Fixes #47202
Fixes #43716

Tests

This PR include parameterized test (to avoid two identical tests differing in one detail). But if it is not ok, i'll split them.

I added the following tests:

  • Snackbar Position (group test)
    • behavior is fixed and scaffold has no other elements
    • behavior is floating and scaffold has no other elements
    • behavior is fixed and scaffold has bottom navigation bar
    • behavior is floating and scaffold has bottom navigation bar
    • behavior is fixed and scaffold has floating action button
    • behavior is floating and scaffold has floating action button
    • behavior is fixed and scaffold has FAB and bottom navigation bar
    • behavior is floating and scaffold has FAB and bottom navigation bar

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.
  • 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.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. work in progress; do not review labels Dec 22, 2019
@filaps filaps changed the title fixed issue where snack bar position was higher then should be fixed issue where SnackBar position was higher then should be Dec 22, 2019
@filaps filaps marked this pull request as ready for review December 22, 2019 15:34
@filaps filaps changed the title fixed issue where SnackBar position was higher then should be [WIP] fixed issue where SnackBar position was higher then should be Dec 23, 2019
@filaps filaps changed the title [WIP] fixed issue where SnackBar position was higher then should be fixed issue where SnackBar position was higher then should be Dec 23, 2019
@filaps filaps closed this Dec 23, 2019
@filaps filaps reopened this Dec 23, 2019
@shihaohong shihaohong self-assigned this Jan 3, 2020
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

Thank you for the submission! The implementation and the tests look great functionally. I think the most work that'll need to be done following up is that the code can be better formatted such that future readers of the code can easily understand what the intent behind the tests are. I made some higher level comments, but take a look at the Flutter style guide when you're unsure on formatting.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not want to sound too particular, but we use American English in flutter/flutter. There are some mistakes/accidents that happen elsewhere in the codebase, but they weren't intentional :)

Suggested change
String getEnumStringValue(SnackBarBehavior behaviour) => behaviour.toString().split('.').last;
String getEnumStringValue(SnackBarBehavior behavior) => behavior.toString().split('.').last;

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 removed this function :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that we will be adding a lint soon that requires all usages of for (foo in bar) to have the final keyword in it.

Suggested change
for (SnackBarBehavior behavior in SnackBarBehavior.values) {
for (final SnackBarBehavior behavior in SnackBarBehavior.values) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested printing ${SnackBarBehavior.fixed.toString()} and it seems to turn out just fine. Also, describe the expected result for the test in the title. Maybe something like the following:

Suggested change
testWidgets('behavior is ${getEnumStringValue(behavior)} and scaffold has no other elements',
testWidgets('$behavior should align with the bottom of the Scaffold when the Scaffold has no other elements',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one difference in the result string:
for $behavior the result is "SnackBarBehavior.fixed";
for getEnumStringValue(behavior) the result is "fixed".
But now i think this difference is not important. Therefore i will remove the function getEnumStringValue and will use $behavior instead.

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 have added expected results in titles. Is it normal that new test titles have two lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it's ok -- I find that it is difficult to come up with a title that fits in one line that is short enough to be within the 80-character guideline. Plus, I would not have to give up clarity in explaining my test this way

Comment on lines 455 to 466
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the indentations on these lines. Every new line generally has two spaces. ie.

      testWidgets(
        'behavior is ${getEnumStringValue(behavior)} and scaffold has no other elements',
        (WidgetTester tester) async {
          //...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't hurt to test that the bottom left corners of the SnackBar and Scaffold align

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 have added a conditions for the left and right corner of snackBar in all new tests except tests with FAB and SnackBarBehavior.floating.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
floatingActionButton: FloatingActionButton(onPressed: () {},),
floatingActionButton: FloatingActionButton(onPressed: () {}),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
scaffoldState.showSnackBar(const SnackBar(content: Text('Snackbar text'), behavior: SnackBarBehavior.floating,));
scaffoldState.showSnackBar(
const SnackBar(
content: Text('Snackbar text'),
behavior: SnackBarBehavior.floating,
),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as above regarding the title of the test and code indentation/style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as above regarding the title of the test and code indentation/style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
scaffoldState.showSnackBar(const SnackBar(content: Text('Snackbar text'), behavior: SnackBarBehavior.floating,));
scaffoldState.showSnackBar(
const SnackBar(
content: Text('Snackbar text'),
behavior: SnackBarBehavior.floating,
),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@shihaohong shihaohong changed the title fixed issue where SnackBar position was higher then should be Fix SnackBar placement due to FloatingActionButton positioning Jan 3, 2020
@shihaohong
Copy link
Contributor

I hope you don't mind, but I also edited your first comment to use GitHub markdown and clarify the title of the pull request if that's okay with you!

@shihaohong shihaohong changed the title Fix SnackBar placement due to FloatingActionButton positioning Fix SnackBar clipping when it is floating due to FloatingActionButton positioning Jan 3, 2020
@filaps filaps force-pushed the bugfix/snackbar branch 2 times, most recently from 15e5326 to 64ac431 Compare January 7, 2020 16:55
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

I just noticed that there is a test/material/snack_bar_test.dart file, and that it does include some positioning tests. You might want to take a look at the existing tests to ensure that you're not duplicating some tests and maybe look to see why the existing tests are not catching the clipping issue this PR fixes.

Also, the tests you've written might actually belong in snack_bar_test.dart as well :)

Sorry for not noticing this sooner! Let me know if you need any suggestions or help with this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
'when scaffold has no other elements',
'when Scaffold has no other elements',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
});
},
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in all new tests

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: trailing comma

Suggested change
body: Container()
body: Container(),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
});
},
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'$behavior should align snackBar with the bottom of Scaffold '
'$behavior should align SnackBar with the bottom of Scaffold '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'$behavior should align snackBar with the top of bottom navigation bar '
'$behavior should align SnackBar with the top of bottom navigation bar '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'${SnackBarBehavior.fixed} should align snackBar with the bottom of Scaffold '
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'${SnackBarBehavior.floating} should align snackBar with the top of FloatingActionButton'
'${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'${SnackBarBehavior.fixed} should align snackBar with the top of BottomNavigationBar '
'${SnackBarBehavior.fixed} should align SnackBar with the top of BottomNavigationBar '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'${SnackBarBehavior.floating} should align snackBar with the top of FloatingActionButton '
'${SnackBarBehavior.floating} should align SnackBar with the top of FloatingActionButton '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@filaps
Copy link
Contributor Author

filaps commented Jan 8, 2020

I just noticed that there is a test/material/snack_bar_test.dart file, and that it does include some positioning tests. You might want to take a look at the existing tests to ensure that you're not duplicating some tests and maybe look to see why the existing tests are not catching the clipping issue this PR fixes.

Also, the tests you've written might actually belong in snack_bar_test.dart as well :)

Sorry for not noticing this sooner! Let me know if you need any suggestions or help with this PR

Thank you for this notice.
I did not look snak_bar_test.dart carefully.
I was sure that testing the position of the elements is the responsibility of the scaffold, and so I thought that the tests should be in scaffold_test.dart. :)

Now i analyzed snackbar_test.dart:

I found 4 tests with SnackBar position which look like my tests:

  1. SnackBar is positioned above BottomNavigationBar
  2. SnackBar should push FloatingActionButton above
  3. Floating SnackBar is positioned above BottomNavigationBar
  4. Floating SnackBar is positioned above FloatingActionButton

Test 1:
This test has a very complicated "expected" part:


    expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding
    expect(snackBarBottomLeft.dy - textBottomLeft.dy, 17.0); // margin (with no bottom padding)
    expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0);
    expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 30.0); // margin + right padding
    expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 17.0); // margin (with no bottom padding)

In this case, the SnackBar position is calculated using the content of the SnackBar and the action of the SnackBar.
Moreover, there are many excess details in the test, such as the BottomNavigationBar widget (for example: in my case it is just a SizedBox), GestureDetecter and too detailed SnackBar.
The test has magic numbers. I spent a lot of time realizing what they mean
Test 2:
This test is good. It makes sure the button goes up when the SnackBar appears.
but it just check that y position of FAB more then y position of SnackBar.
i can improve the test by check the exact position of the FAB after the appearance of SnackBar.
Test 3:
This test should catch a bug, but it skips it.
expect (snackBarBottomRight.dy - actionTextBottomRight.dy, 27.0) This line checks that the distance between the action and the SnackBar border is 27, but does not check at what y position of the SnackBar is now. (same problem in test 1)
Test 4:
This is the correct test, but a lot of excess details in my opinion.
Its advantage is that it checks for padding, but I would move the checks for padding to a separate test.

In total:

  • I think test 1 should be replaced with my test ('$behavior should align snackBar with the top of bottom navigation bar when Scaffold has no FloatingActionButton')
  • Improve test 2
  • test 3 has all the same problems as test 1. I also suggest replacing it with my test.
  • Remove excess details from the test 4.
  • move all my tests (except ${SnackBarBehavior.floating} should align snackBar with the top of FloatingActionButton' 'when Scaffold has a FloatingActionButton') to snack_bar_test.dart
  • maybe separate tests that check SnackBar position when Scaffold has a padding

@shihaohong
Copy link
Contributor

shihaohong commented Jan 10, 2020

I was sure that testing the position of the elements is the responsibility of the scaffold, and so I thought that the tests should be in scaffold_test.dart. :)

That's okay, I had the same thoughts :)

Test 1:
This test has a very complicated "expected" part:


    expect(textBottomLeft.dx - snackBarBottomLeft.dx, 24.0 + 10.0); // margin + left padding
    expect(snackBarBottomLeft.dy - textBottomLeft.dy, 17.0); // margin (with no bottom padding)
    expect(actionTextBottomLeft.dx - textBottomRight.dx, 24.0);
    expect(snackBarBottomRight.dx - actionTextBottomRight.dx, 24.0 + 30.0); // margin + right padding
    expect(snackBarBottomRight.dy - actionTextBottomRight.dy, 17.0); // margin (with no bottom padding)

In this case, the SnackBar position is calculated using the content of the SnackBar and the action of the SnackBar.
Moreover, there are many excess details in the test, such as the BottomNavigationBar widget (for example: in my case it is just a SizedBox), GestureDetecter and too detailed SnackBar.
The test has magic numbers. I spent a lot of time realizing what they mean

Hmm, this seems to more so test the margins/padding between the edges of SnackBar and its contents. Perhaps keeping it and renaming the test would suffice?

Test 2:
This test is good. It makes sure the button goes up when the SnackBar appears.
but it just check that y position of FAB more then y position of SnackBar.
i can improve the test by check the exact position of the FAB after the appearance of SnackBar.
Sounds good! If it's an easy change to make, I'd welcome it :)

Test 3:
This test should catch a bug, but it skips it.
expect (snackBarBottomRight.dy - actionTextBottomRight.dy, 27.0) This line checks that the distance between the action and the SnackBar border is 27, but does not check at what y position of the SnackBar is now. (same problem in test 1)

Same comment as with test 1, let's keep the test for now and just rename it such that it's clear that it checks for margin/padding correctness.

Test 4:
This is the correct test, but a lot of excess details in my opinion.
Its advantage is that it checks for padding, but I would move the checks for padding to a separate test.

Seems like a great idea!

In total:

  • I think test 1 should be replaced with my test ('$behavior should align snackBar with the top of bottom navigation bar when Scaffold has no FloatingActionButton')
  • Improve test 2
  • test 3 has all the same problems as test 1. I also suggest replacing it with my test.
  • Remove excess details from the test 4.
  • move all my tests (except ${SnackBarBehavior.floating} should align snackBar with the top of FloatingActionButton' 'when Scaffold has a FloatingActionButton') to snack_bar_test.dart
    maybe separate tests that check SnackBar position when Scaffold has a padding

I think for test 1, 3 and 4, what we could do is add your tests, and then take out the margin/padding sections of the preexisting tests and make them into new tests. That way, we don't remove tests for expected padding, while incorporating your positioning tests.

Any idea why the original tests never caught the error case? Is it simply because that specific case was never tested?

@filaps
Copy link
Contributor Author

filaps commented Jan 12, 2020

Any idea why the original tests never caught the error case? Is it simply because that specific case was never tested?

yes, that's right.

Perhaps keeping it and renaming the test would suffice?

Good idea, i agree!

take out the margin/padding sections of the preexisting tests and make them into new tests.

I found a test with paddings of SnackBar. In my commit i just improved it by adding universal behavior and checking the leftBottom and rightBottom points of SnackBar.

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

This looks much better than it used to before, thanks again for doing all the refactor!

The only bigger thing is tweaking some tests to fully animate the SnackBar instead of checking the positions of the SnackBar and the FAB only at the very beginning of the animation. Other than that, it's mostly code clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Better to use the same word to describe "the spacing in between widgets" since it might get confusing for future readers when padding/margin/indent is used interchangeably.

Suggested change
'Indent between border and content of SnackBar when behavior is fixed',
'Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const int fabMargin = 16;
// {{Describe wherever this value was derived from}}
const int defaultFabPadding = 16;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I confused origin and original here, since origin can also be interpreted as the reference point of some coordinate system :) Maybe we can make this clearer this way:

    // Get the Rect of the FAB to compare after the SnackBar appears.
    final Offset originalFabRect = tester.getRect(find.byType(FloatingActionButton));
    
    // Code that makes SnackBar appear.
    
    // FAB should shift upwards after SnackBar appears.
    expect(originalFabRect.getBottomRight.dy > fabBottomRight.dy, true);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(snackBarTopRight.dy - fabMargin, equals(fabBottomRight.dy));
// FAB should be positioned above the SnackBar by the default padding.
expect(snackBarTopRight.dy - fabMargin, equals(fabBottomRight.dy));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Indent between border and content of SnackBar when behavior is floating',
'Custom padding between SnackBar and its contents when set to SnackBarBehavior.floating',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
find.byType(FloatingActionButton));
find.byType(FloatingActionButton),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is snackBarBox? If it's referring to the RenderBox of the SnackBar, maybe generalizing the term might be better:

Suggested change
// Since padding and margin is handled inside snackBarBox,
// Since padding between the SnackBar and the FAB is created by the SnackBar,
// the bottom offset of the SnackBar should be equal to the top offset of the FAB.

Edit: I realized later that this piece was copy-pasted, but this is a good opportunity to clean this up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could just do:

Suggested change
expect(snackBarBottomCenter.dy == floatingActionButtonTopCenter.dy, true);
expect(snackBarBottomCenter.dy, floatingActionButtonTopCenter.dy);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await tester.pump();
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await tester.pump();
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@shihaohong
Copy link
Contributor

Bonus points if you could get a screenshot with the fix and put it in the first comment of the issue. That helps 1) verify that the fix is as expected and 2) helps future maintainers of the code understand what the intent of this change was

shihaohong
shihaohong previously approved these changes Jan 30, 2020
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

Thank you for your patience, I was on vacation and am just getting back into the groove of things :) Pretty much good except for a few variable names in a test (they test the correct behavior though)

Copy link
Contributor

Choose a reason for hiding this comment

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

Use lessThan matcher here:

Suggested change
expect(originalFabRect.center.dy > fabRect.center.dy, true);
expect(fabRect.center.dy, lessThan(originalFabRect.center.dy));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// value was derived from floating_action_button_location.dart
// FAB's surrounding padding is set to [kFloatingActionButtonMargin] in floating_action_button_location.dart byb default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

the order is expect(actual, expected), so since fabRect is the actual Rect, it should appear first

Suggested change
expect(snackBarTopRight.dy - defaultFabPadding, fabRect.bottomRight.dy);
expect(fabRect.bottomRight.dy, snackBarTopRight.dy - defaultFabPadding);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
await tester.pumpAndSettle(); //Have the SnackBar fully animate out.
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
}
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final Offset snackBarBottomCenter = tester.getBottomLeft(find.byType(SnackBar));
final Offset snackBarBottomLeft = tester.getBottomLeft(find.byType(SnackBar));

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final Offset floatingActionButtonTopCenter = tester.getTopLeft(
final Offset floatingActionButtonTopLeft = tester.getTopLeft(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(snackBarBottomCenter.dy, floatingActionButtonTopCenter.dy);
expect(snackBarBottomLeft.dy, floatingActionButtonTopLeft.dy);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@shihaohong shihaohong self-requested a review January 30, 2020 20:39
@shihaohong shihaohong dismissed their stale review January 30, 2020 20:39

Accidentally approved despite wanting a few more changes

@filaps filaps force-pushed the bugfix/snackbar branch 2 times, most recently from acc8ce7 to f96641d Compare February 1, 2020 12:27
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// FAB's surrounding padding is set to [kFloatingActionButtonMargin] in floating_action_button_location.dart byb default.
// FAB's surrounding padding is set to [kFloatingActionButtonMargin] in floating_action_button_location.dart by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
}
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@shihaohong
Copy link
Contributor

All presubmit tests seem to be passing. Once the tree is green, this will be merged.

Thank you so much for this contribution and for taking the time to address all feedback!

@filaps
Copy link
Contributor Author

filaps commented Feb 6, 2020

All presubmit tests seem to be passing. Once the tree is green, this will be merged.

Thank you so much for this contribution and for taking the time to address all feedback!

Thank you for review, it was a pleasure to work with you!

Now the test checks certain position Y of FAB
added tests for testing height of SnackBar.
…n' to group 'SnackBar position'

improved test by removing padding details, and renaming.
… group "SnackBar position"

and improved test for testing with universal behavior
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite build_tests-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@shihaohong
Copy link
Contributor

shihaohong commented Feb 6, 2020

The presubmit tests seem to have rerun for some reason and build_tests-linux is failing on a 504 gateway timeout error (unrelated to your change)

@fluttergithubbot fluttergithubbot merged commit 801a6a7 into flutter:master Feb 8, 2020
shihaohong pushed a commit that referenced this pull request Feb 10, 2020
shihaohong pushed a commit that referenced this pull request Feb 10, 2020
shihaohong pushed a commit that referenced this pull request Feb 11, 2020
…tingActionButton positioning (#47616)" (#50516)"

This reverts commit 67826bd.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

Floating Snackbar has clipped shadow Floating snackbar wrong placement

5 participants