Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Jul 8, 2022

Avoid situations where users place scrollable content in a Column just so they can wrap it in a Container to add some kind of BoxDecoration. For example, I've seen stuff like:

CustomScrollView(
  slivers: [
    SliverToBoxAdaptor(
      child: Container(
         color: Colors.red,
         child: Column( ...),
      ),
    ),
  ]
)

Which totally defeats the purpose of scroll views

@flutter-dashboard flutter-dashboard bot added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels Jul 8, 2022
@jonahwilliams jonahwilliams marked this pull request as ready for review July 8, 2022 18:16
Jonah Williams added 3 commits July 8, 2022 11:35
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #107269 at sha 7939874

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jul 8, 2022
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #107269 at sha a5bb029

@jonahwilliams
Copy link
Contributor Author

I don't think the golden tests I added are super useful, I'll update them a bit so they actually have some content

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #107269 at sha a3822f6

@jonahwilliams jonahwilliams changed the title [framework] DecoratedSliver [framework] SliverDecoration Jul 11, 2022
@jonahwilliams
Copy link
Contributor Author

Renamed to SliverDecoration to matching existing sliver widgets

@Piinks Piinks added the c: new feature Nothing broken; request for a new capability label Jul 11, 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.

Love this! 😻

Can you add a reference in the docs for DecoratedBox and/or BoxDecoration to make this more discoverable?


/// Paints a [Decoration] either before or after its child paints.
class RenderSliverDecoration extends RenderProxySliver {
/// Creates a decorated box.
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
/// Creates a decorated box.
/// Creates a decorated sliver.

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

@jonahwilliams
Copy link
Contributor Author

I added some breadcrumbs to the "see also" section of the BoxDecoration and DecoratedBox docs

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-very

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #107269 at sha ceef37a

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 12, 2022
@auto-submit auto-submit bot merged commit 881b27e into flutter:master Jul 12, 2022
@Kavantix
Copy link
Contributor

Kavantix commented Jul 12, 2022

A widget like this is super useful but this implementation should be reverted IMHO, sorry @jonahwilliams.
There are a couple things wrong here:

  1. It doesnt work in horizontal scrollviews, (@Piinks I tested it to confirm)
  2. It uses the paintExtent of the child which isn't always the correct value to use, take for instance this example when applying a rounde corner. The bottom two corners shouldn't be rounded yet.

image

  1. Overlap and other advanced properties of slivers aren't accounted for.
  2. Nit: The name is inconsistent with the box counterpart DecoratedBox, this should be called DecoratedSliver.

The correct behaviour should be the same as using a SliverStack from sliver_tools with a SliverPositioned.fill behind the second child sliver.

@Piinks @jonahwilliams let me know if you rather have a new ticket created for these issues, but I stand by my point that this current implementation should NOT reach stable or beta channels if possible. It will create more issues than it solves.

@jonahwilliams
Copy link
Contributor Author

Well the only one I can immediately disagree with is 4, which is that I chose the name to be consistent with the other sliver widgets like SliverPadding and SliverList. 🐈

I agree we should fix those other issues, it would be helpful if you could file bugs for the specific ones you've noticed here. Thanks!

@Kavantix
Copy link
Contributor

Well the only one I can immediately disagree with is 4, which is that I chose the name to be consistent with the other sliver widgets like SliverPadding and SliverList. 🐈

Well this name suggests it’s a counterpart to BoxDecoration

@Kavantix
Copy link
Contributor

And probably there should actually be a SliverDecoration that has specific properties related to decorating slivers rather than boxes

@jonahwilliams
Copy link
Contributor Author

Yes, but then it would be named differently from all of the other Sliver* widgets

@Kavantix
Copy link
Contributor

You could technically name it SliverDecorated or SliverWithDecoration but DecoratedSliver is both nicer and more discoverable for someone that knows about DecoratedBox
This is also how I ended up with the name MultiSliver in sliver_tools, there just want a good name that started with Sliver, covered the load and wasnt unwieldy

@jonahwilliams
Copy link
Contributor Author

I like SliverDecorated

@jonahwilliams
Copy link
Contributor Author

but its a bit odd still IMO, we don't do past tense for the most part. I.e. its SliverPadding and not SliverPadded

@Kavantix
Copy link
Contributor

I agree and wouldnt have even mentioned the name if it werent for BoxDecoration not being the widget but the configuration. And we’ll run into this same thing when inevitably adding a Sliver counterpart to ColoredBox.

Perhaps in light of this and the widget not being finished it would make more sense to not put it in the framework itself just yet?

jonahwilliams pushed a commit that referenced this pull request Jul 13, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
@thkim1011 thkim1011 mentioned this pull request May 30, 2023
auto-submit bot pushed a commit that referenced this pull request Jun 20, 2023
This is a second attempt to merge #107269. Currently I've fixed two of the issues:
1. Fixed horizontal scrollview by using a switch statement to consider vertical/horizontal case.
2. Fixed issue of `paintExtent` not being the right extent for painting. Rather using a `scrollExtent` for the main axis length of the decoration box and painting it offsetted by the `scrollOffset`.
3. If the sliver child has inifinite scrollExtent, then we only draw the decoration down to the bottom of the `cacheExtent`. The developer is expected to ensure that the border does not creep up above the cache area.

This PR includes a test that checks that the correct rectangle is drawn at a certain scrollOffset for both the horizontal and vertical case which should be sufficient for checking that `SliverDecoration` works properly now.

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

Labels

autosubmit Merge PR when tree becomes green via auto submit App c: new feature Nothing broken; request for a new capability f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants