fluttercommunity / flutter_sticky_headers

Flutter Sticky Headers - Lets you place "sticky headers" into any scrollable content in your Flutter app. No special wrappers or magic required. Maintainer: @slightfoot
https://pub.dev/packages/sticky_headers
MIT License
1.07k stars 130 forks source link

Sticky Header Crash #42

Closed xuhongfei closed 2 years ago

xuhongfei commented 3 years ago
Screen Shot 2020-10-29 at 07 11 04 Screen Shot 2020-10-29 at 07 27 12 Screen Shot 2020-10-29 at 07 15 36

if itemCount set to 2, will cause crash.

Widget _buildBody(BuildContext context) {
    return ListView.builder(
      controller: _scrollController,
      physics: BouncingScrollPhysics(),
      itemCount: 2,
      itemBuilder: (context, index) {
        return StickyHeader(
          overlapHeaders: true,
          header: Container(
            height: 50.0,
            color: MyColors.lightGrayColor,
            padding: EdgeInsets.symmetric(horizontal: 16.0),
            alignment: Alignment.centerLeft,
            child: Text('Header #$index',
              style: const TextStyle(color: Colors.white),
            ),
          ),
          content: _buildContent(context),
        );
      },
    );
  }

  Widget _buildContent(BuildContext context) {
    return GridView.builder(
      controller: _scrollController,
      shrinkWrap: true,
      physics: BouncingScrollPhysics(),
      itemCount: 30,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        mainAxisSpacing: 1,
        crossAxisSpacing: 1,
        childAspectRatio: 1,
      ), 
      itemBuilder: (BuildContext context, int index) {
        return Container(
          height: 44,
          color: MyColors.backgroundColor,
          child: Text(index.toString()),
        );
      },
    );
  }

@brianegan , pls help to check this crash. Thanks a lot!

xuhongfei commented 3 years ago
NiklaesAtShortcut commented 3 years ago

I am facing the same issue.

slightfoot commented 2 years ago

Cannot replicate this issue from the example above on Flutter 3.0.0. Please retest. I also noticed your using the same controller in both ListView and GridView widgets and that can cause an issue.