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

[BUG] CustomScrollView with "center" scrolls backwards #77

Open
Areopagitics opened this issue Jul 21, 2022 · 3 comments
Open

[BUG] CustomScrollView with "center" scrolls backwards #77

Areopagitics opened this issue Jul 21, 2022 · 3 comments

Comments

@Areopagitics
Copy link

When using center key, the header gets stuck on the bottom. I wondering if there is a way to simply display headers for months and years indefinitely starting at a certain date in the center. There seems to be no easy way to solve this problem in Flutter.


return CustomScrollView(
        cacheExtent: 300.0,
        center: centerKey,
        anchor: 0.5,
        slivers: <Widget>[
          _rowBuilder(context, date, -1),
          SliverList(
            key: centerKey,
            delegate: SliverChildListDelegate([
              Column(
                children: [
                  Divider(),
                  Container(
                    color: Color.fromARGB(255, 174, 12, 0),
                    child: Text('data'),
                  ),
                  Divider(),
                ],
              ) 
            ]),
          ),
          _rowBuilder(context, date, 1),
        ],
      );

@Areopagitics Areopagitics changed the title CustomScrollView "center" not working [BUG] [BUG] CustomScrollView "center" backwards Jul 21, 2022
@Areopagitics Areopagitics changed the title [BUG] CustomScrollView "center" backwards [BUG] CustomScrollView with "center" scrolls backwards Jul 23, 2022
@JChPal
Copy link

JChPal commented Dec 27, 2022

I'm also stuck on this, did you find any workaround ?

I also made a full example

import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

const customScrollViewCenterKey = ValueKey('customScrollViewCenterKey');

class SliverStickyHeaderCustomScrollViewIssue extends StatelessWidget {
  const SliverStickyHeaderCustomScrollViewIssue({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          const SliverAppBar(
            title: Text('CustomScrollView center issue'),
          ),
        ];
      },
      body: CustomScrollView(
        center: customScrollViewCenterKey,
        slivers: <Widget>[
          /// before CustomScrollView center ValueKey
          SliverStickyHeader(
            header: Container(
              color: Colors.grey,
              child: const Padding(
                padding: EdgeInsets.all(24),
                child: Text('Sticky before CustomScrollView center ValueKey'),
              ),
            ),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                (_, index) {
                  return Padding(
                    padding: const EdgeInsets.all(16),
                    child: Text('Child reversed $index'),
                  );
                },
                childCount: 15,
              ),
            ),
          ),

          /// CustomScrollView center ValueKey
          const SliverToBoxAdapter(
            key: customScrollViewCenterKey,
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child: Text('CustomScrollView center'),
            ),
          ),

          /// After CustomScrollView center ValueKey
          SliverStickyHeader(
            header: Container(
              color: Colors.grey,
              child: const Padding(
                padding: EdgeInsets.all(24),
                child: Text('Sticky after CustomScrollView center ValueKey'),
              ),
            ),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                (_, index) {
                  return Padding(
                    padding: const EdgeInsets.all(16),
                    child: Text('Child $index'),
                  );
                },
                childCount: 15,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

@JChPal
Copy link

JChPal commented Dec 27, 2022

This issue is similar to this one : #11

I make it work with @charlesRmajor fork

  flutter_sticky_header:
    git:
      url: https://github.com/charlesRmajor/flutter_sticky_header
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

const customScrollViewCenterKey = ValueKey('customScrollViewCenterKey');

class SliverStickyHeaderCustomScrollViewIssue extends StatelessWidget {
  const SliverStickyHeaderCustomScrollViewIssue({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          const SliverAppBar(
            title: Text('CustomScrollView center issue'),
          ),
        ];
      },
      body: CustomScrollView(
        center: customScrollViewCenterKey,
        slivers: <Widget>[
          /// before CustomScrollView center ValueKey
          /// ======MODIFIED CODE
          SliverStickyHeader.builder(
            reverse: true,
            /// ======MODIFIED CODE
            builder: (context, constraint) => Container(
              color: Colors.grey,
              child: const Padding(
                padding: EdgeInsets.all(24),
                child: Text('Sticky before CustomScrollView center ValueKey'),
              ),
            ),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                (_, index) {
                  return Padding(
                    padding: const EdgeInsets.all(16),
                    child: Text('Child reversed $index'),
                  );
                },
                childCount: 15,
              ),
            ),
          ),

          /// CustomScrollView center ValueKey
          const SliverToBoxAdapter(
            key: customScrollViewCenterKey,
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child: Text('CustomScrollView center'),
            ),
          ),

          /// After CustomScrollView center ValueKey
          SliverStickyHeader(
            header: Container(
              color: Colors.grey,
              child: const Padding(
                padding: EdgeInsets.all(24),
                child: Text('Sticky after CustomScrollView center ValueKey'),
              ),
            ),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                (_, index) {
                  return Padding(
                    padding: const EdgeInsets.all(16),
                    child: Text('Child $index'),
                  );
                },
                childCount: 15,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Do you known if the @charlesRmajor change will be integrate in your package?

@Areopagitics
Copy link
Author

Areopagitics commented Dec 29, 2022

I've tried so many different options, I ended up going with a SingleChildScroll with a scroll controller for my particular need (but it's slow and janky) ... I'm kinda banking on this though #108289 . It was reopened ... I would recommend making some more noise over there (I think the issue describes the overall problem in Flutter). Long-term it's better to get at the root of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants