Skip to content

Conversation

@spkersten
Copy link
Contributor

@spkersten spkersten commented May 21, 2019

Description

A widget like Column but for Slivers.

Related Issues

#33137

Tests

TODO: not entirely clear how to properly test the big parameter space of slivers.

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

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read [Handling breaking changes]). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label May 23, 2019
@goderbauer
Copy link
Member

It is not super-clear to me what the use case for such a sliver is. Can you elaborate (and possibly also update the documentation)? Why not throw all those slivers in a CustomScrollView?

@spkersten
Copy link
Contributor Author

spkersten commented May 31, 2019

@goderbauer I've added an example to the documentation. In the example the purpose it not to duplicate the same padding for every sliver. While for padding that would still be possible (but bad), for other cases it isn't: I've made a CrossAxisContraintSliver that, like ContraintBox, lets you constrain the maximum width of a child sliver and centring the child when needed. If you want to keep a group of slivers aligned by their left edge, you can't wrap them individually in CrossAxisContraintSliver.

Another kind of use cases is creating abstractions. Let's say I want to make a widget that is composed of a heading and a SliverList:

class ListItemGroup extends StatelessWidget {
  Widget build(BuildContext context) =>
    SliverGroup(
      slivers: [
        SliverToBoxAdapter(child: heading),
        SliverList(items),
    );
}

which is used like this:

CustomScrollView(
  slivers: [
    SliverAppBar(...),
    ListItemGroup(...),
    ListItemGroup(...),
  ],
);

@goderbauer
Copy link
Member

That does sound like a valid use case. This could also live as an external package on pub, though. Is there any reason you feel like this belong in the framework?

@spkersten
Copy link
Contributor Author

It felt fundamental enough to be part of the framework, not very different from Column or Row. This one is to test the water, so to speak, I've also missed (and needed to create) sliver versions of Stack, LayoutBuilder, CustomPaint, ClipRRect. These seem like basic widgets that the framework should offer. On the other hand, you could argue that, since no one else has asked for them, maybe they aren't really needed.

@goderbauer
Copy link
Member

In those cases it may be a good idea to implement them in an external package first. This would allow for fast iterations. When we add something to the framework we have to be sure that it has a reasonable stable API. If the package turns out to be popular, we can always pull it into the framework...

@spkersten
Copy link
Contributor Author

spkersten commented Jun 14, 2019 via email

@Piinks Piinks added the would be a good package Separate Flutter package should be made for this label Jun 14, 2019
@spkersten spkersten closed this Jun 15, 2019
@Piinks
Copy link
Contributor

Piinks commented Oct 31, 2019

I tested this a few months ago during review. There were some cases where it broke, but I've incorporated bits of it into the larger project of Sliver[Flex, Group, Expanded, Spacer]. I should have a PR open for discussion & feedback soon.

@Piinks Piinks reopened this Oct 31, 2019
@fluttergithubbot
Copy link
Contributor

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.

@Piinks
Copy link
Contributor

Piinks commented Oct 31, 2019

Clicked comment & re-open instead of just comment. 😅

@Piinks Piinks closed this Oct 31, 2019
@abdulghani
Copy link

@spkersten do you cover for horizontal row case?
like putting two or more slivers beside of each other
it seems you only provide vertical column case for putting slivers there

@spkersten
Copy link
Contributor Author

@abdulghani I think a widget that groups slivers along the cross-axis direction would not be too hard to make; certainly easier than along the main-axis as I tried here. I might give it a try. I've been meaning to open source several missing sliver widgets, but I got a bit discouraged so it didn't materialise yet.

@jamesblasco
Copy link
Contributor

Hello @spkersten, I have a project where a SliverGroup is quite necessary. The page has a lot of different sections and wrapping all inside a StatefulWidget sounds a terrible idea. I have been using this as my custom SliverGroup. But I wonder if you think your solution is usable for a stable project. It would be very valuable to use, I think it is the most important sliver missing.

class SliverSection extends StatelessWidget {
  final List<Widget> slivers;

  const SliverSection({Key key, this.slivers}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: ShrinkWrappingViewport(
        offset: ViewportOffset.zero(),
        slivers: slivers,
      ),
    );
  }
}```

@spkersten
Copy link
Contributor Author

@jamesblasco We are using it quite extensively (for the modularisation reason you mention) in two of our released app. If you are putting simple slivers in it (lists, grids, slivertoboxadapters) it should work fine; fancier slivers (fill remaining, persistent header, special custom ones) might not work correctly in the group as that hasn't been tested to the same extent.

@jamesblasco
Copy link
Contributor

jamesblasco commented Jun 15, 2020

Thank you!! Perfect for the moment I am not using anything fancier inside.

@scopendo
Copy link

We are using it quite extensively (for the modularisation reason you mention) in two of our released app.

@spkersten – sorry if I've missed it or misunderstood, is your sliver package available on pub.dev?

@spkersten
Copy link
Contributor Author

@scopendo I never got around making a package. However, there is sliver_tools that contains a widget that seems to offer the same functionality.

@jamesblasco
Copy link
Contributor

jamesblasco commented Dec 23, 2020

If you give me your permission @spkersten to use this code, I would be happy to use it with some modifications to build a package out of it, also adapt it for null-safety and add tests.

I have been using it for some projects and I find it super useful

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

Labels

framework flutter/packages/flutter repository. See also f: labels. would be a good package Separate Flutter package should be made for this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants