Skip to content
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

Add a widget similar to SliverFillRemaining but allows for a minimum scroll amount #22

Open
Kypsis opened this issue Jan 20, 2021 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Kypsis
Copy link

Kypsis commented Jan 20, 2021

Changes from 0.1.9 to 0.1.10 break passing constraints to children:

class ExampleWidget extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MultiSliver(
      children: [
        SliverList(
                delegate: SliverChildBuilderDelegate((context, index) {
                  return ExampleItemWidget();
                }, childCount: exampleData.length),
              ),

        SliverFillRemaining(
            hasScrollBody: false,
            child: Container())
      ],
    );
  }
}

In 0.1.9 the SliverFillRemaining correctly filled the remaining space in the list if there are not enough items in the list to allow for the Multisliver to expand and fill the viewport in a CustomScrollView that already has a preceding flexible SliverAppBar. Or more succinctly 0.1.10 changes caused the child of SliverFillRemaining in MultiSliver to always have a height of 0.

@Kavantix
Copy link
Owner

I cannot reproduce your issue.
Could you provide a complete and minimal example?

@Kypsis
Copy link
Author

Kypsis commented Jan 20, 2021

Parent widget would be:

class ExampleParentScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
          extendBody: true,
          backgroundColor: Themes.white,
          bottomNavigationBar: const NavigationWidget(),
          body: CustomScrollView(
            physics: BouncingScrollPhysics(),
            slivers: <Widget>[
              const ExampleAppBarWidget(),
              const ExampleWidget()
            ],
          ),
        );
      },
}

And ExampleAppBarWidget:

class ExampleAppBarWidget extends StatelessWidget {
  static const double collapsedHeight = 57.0;
  static const double expandedHeight = 465.0;

  const ExploreAppBarWidget();

  @override
  Widget build(BuildContext context) {
    return SliverPersistentHeader(
      pinned: true,
      delegate: _SliverAppBarDelegate(
          minHeight: collapsedHeight + MediaQuery.of(context).padding.top,
          maxHeight: expandedHeight + MediaQuery.of(context).padding.top),
    );
  }
}

class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  final double minHeight;
  final double maxHeight;

  _SliverAppBarDelegate({
    @required this.minHeight,
    @required this.maxHeight,
  });

  @override
  double get minExtent => minHeight;

  @override
  double get maxExtent => max(maxHeight, minHeight);

  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
          color: Colors.red
    );
  }

  @override
  bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
    return false;
  }
}

@Kavantix
Copy link
Owner

Using your code and having the child as a simple container:

class ExampleItemWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      width: double.infinity,
      color: Colors.green,
      margin: const EdgeInsets.all(8),
    );
  }
}

I get this result when setting the fillremaining to blue so it seems to work
Simulator Screen Shot - iPhone 12 - 2021-01-20 at 15 33 41

Are you using 0.1.10+1?

@Kypsis
Copy link
Author

Kypsis commented Jan 20, 2021

Now Imagine scrolling up so the appbar collapses: the red gets smaller, and the blue gets proportionally bigger. In 1.0.9 that was the behaviour if you didn't specify height to the Container (or SizedBox). In 1.1.10+1 the blue part wont resize so the appbar is not collapsable. You could give a scrollbody to the SliverFillRemaining but then the blue part would be viewport height, and the green list items would be scrollable offscreen. The intended behaviour is that if I have less items in the list than would fill the screen, then SliverFillRemaining would fill the missing part so the appbar is fully collapsable (otherwise the appbar would only be collapsable to the extent I have list items).

The use case would be a situation where I can add and remove items to and from the list. Or better example, I wouldn't want a situation where I only see partly expanded or collapsed appbar assuming I'm showing different content whether it is fully expanded or collapsed.

@Kavantix
Copy link
Owner

Kavantix commented Jan 20, 2021

Sadly I must tell you that the behaviour 0.1.9 had was actually incorrect.
The current version behaves the same as if you didn't place the widgets inside a MuliSliver but directly inside the CustomScrollView.

I do actually have an adapted version of SliverFillRemaining in my private code (it's not open source ready) that allows you to specify a minimum amount of scroll that the SliverFillRemaining should provide.
If you want I can mail it to you and perhaps we can work together to get it included in this package.

@Kavantix Kavantix added enhancement New feature or request good first issue Good for newcomers and removed enhancement New feature or request labels Jan 23, 2021
@Kavantix Kavantix changed the title MultiSliver changes from 0.1.9 to 0.1.10 break passing proper contraints to children. Add a widget similar to SliverFillRemaining but allows for a minimum scroll amount Jan 23, 2021
@Kavantix
Copy link
Owner

Kavantix commented Jan 23, 2021

I have emailed you the current version of the SliverFillRemainingWithMinimum widget
If you agree that it solves this issue we should start on a PR to add it to the package

@martipello
Copy link

how did this end?

@Kavantix
Copy link
Owner

@martipello it wasnt what he needed, feel free to open an issue if you’re running into something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants