-
Notifications
You must be signed in to change notification settings - Fork 29.7k
SliverAppBar - Configurable overscroll stretch with callback feature & FlexibleSpaceBar support #42250
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
cc/ @HansMuller FYI 🙂 |
justinmc
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.
I'm no sliver expert but LGTM 👍
Just some small suggestions here and there.
packages/flutter/lib/src/rendering/sliver_persistent_header.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/rendering/sliver_persistent_header.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/rendering/sliver_persistent_header.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/rendering/sliver_persistent_header.dart
Outdated
Show resolved
Hide resolved
packages/flutter/test/material/flexible_space_bar_stretch_mode_test.dart
Show resolved
Hide resolved
…& FlexibleSpaceBar support (flutter#42250)
|
@Piinks Would this allow a Google Maps instance inside a SliverAppBar, instead of an image? I tried many approaches in the pass with no success. |
Description
SliverAppBar.stretch
This PR introduces the ability to configure a stretch effect for a
SliverAppBarwhen usingScrollPhysicsthat allow overscroll. (i.e. iOS'sBouncingScrollPhysics).This configuration also allows you to specify an amount of overscroll offset that will trigger a given callback function. The default triggering offset distance is 100.0.
This stretch features works with all of the
SliverAppBarconfigurations - floating, pinned, snap, and default scrolling persistent headers all work with stretch.FlexibleSpaceBar
Potential follow-up on this would be to add something along the lines of a stretchMode toFlexibleSpaceBar, similar to the collapseMode that is already provided.The
SliverAppBarchanges alone would leave theFlexibleSpaceBarin a weird state when using the stretch feature, so I have added support here as well.This support comes in the form of
StretchModes, modeled after theCollapseModes that are already a part ofFlexibleSpaceBar. Currently being added here are zoomBackground, blurBackground, and fadeTitle, all of which are in use in the animation below. Providing at least the zoomBackground stretch mode seems prudent since without it an app bar will stretch outside of the background. These stretch modes do not interfere with any of the collapse modes.Code snippet behind this animation:
More Custom Stretching!
While the stretch modes introduced here may not cover every possible stretch behavior, the changes to
SliverAppBaralone make it much easier to implement your own custom behavior for stretching, as the proper constraints will be passed down from theSliverPersistentHeaderto any of its children when stretch is true. For example, the Pesto demo of Flutter Gallery automatically adheres to the stretch, using aLayoutBuilderinstead of aFlexibleSpaceBar. Shown here:A follow-up PR will add animated illustrations to go along with sample code.
Related Issues
Fixes #27373
Tests
I added the following tests:
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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?