0

i have a SliverPersistentHeader that causes bottom overflowed when user scrolls the screen.

Bottom overflowed

How can i fix it?

    return CustomScrollView(
      slivers: <Widget>[
        SliverPersistentHeader(
          pinned: false,
          delegate: DynamicSliverHeaderDelegate(
            maxHeight: 256,
            minHeight: 186,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                _topo(context, grupo),
                _infoGrupo(context, grupo),
              ],
            ),
          ),
        ),

        // TODO: Lista do grupo 
        SliverFillViewport(
          delegate: SliverChildListDelegate(
            [
              Container(
                padding: EdgeInsets.only(top: 100),
                color: Colors.green.withOpacity(0.2),
                child: Column(
                  children: <Widget>[
                    Text('TODO... A construir'),
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    );

// .....

class DynamicSliverHeaderDelegate extends SliverPersistentHeaderDelegate {
  final Widget child;
  final double maxHeight;
  final double minHeight;

  const DynamicSliverHeaderDelegate({
    @required this.child,
    this.maxHeight = 250,
    this.minHeight = 80,
  });

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return child;
  }

  // @override
  // bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) => true;

  @override
  bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) {
    return maxHeight != oldDelegate.maxHeight ||
        minHeight != oldDelegate.minHeight ||
        child != oldDelegate.child;
  }

  @override
  double get maxExtent => maxHeight;

  @override
  double get minExtent => minHeight;
}

2 Answers 2

2

Solved it by wrapping the DynamicSliverHeaderDelegate Column child with a SingleChildScrollView´ withNeverScrollableScrollPhysics` physics.

return CustomScrollView(
  slivers: <Widget>[
    SliverPersistentHeader(
      pinned: false,
      delegate: DynamicSliverHeaderDelegate(
        maxHeight: 256,
        minHeight: 186,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            _topo(context, grupo),
            _infoGrupo(context, grupo),
          ],
        ),
      ),
    ),
    // TODO: Lista do grupo 
    // ...
  ],
);
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, but could you please update your code? it is missing and not showing the final result- thank you!
@romaneso The author explained the solution. To be explicit, I updated the code with the fix in my answer.
0

The complete fix is:

 return CustomScrollView(
      slivers: <Widget>[
        SliverPersistentHeader(
          pinned: false,
          delegate: DynamicSliverHeaderDelegate(
            maxHeight: 256,
            minHeight: 186,
            child: SingleChildScrollView(
              physics: const NeverScrollableScrollPhysics(),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  _topo(context, grupo),
                  _infoGrupo(context, grupo),
                ],
              ),
            ),
          ),
        ),
        // TODO: Lista do grupo
        // ...
      ],
    );
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.