custom_sliver_persistent_header_delegate.dart 785 B

1234567891011121314151617181920212223242526272829303132
  1. import 'package:flutter/material.dart';
  2. class CustomSliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
  3. final double minHeight;
  4. final double maxHeight;
  5. final Widget child;
  6. CustomSliverPersistentHeaderDelegate({
  7. required this.minHeight,
  8. required this.maxHeight,
  9. required this.child,
  10. });
  11. @override
  12. double get minExtent => minHeight;
  13. @override
  14. double get maxExtent => maxHeight;
  15. @override
  16. Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
  17. return Container(
  18. child: child,
  19. );
  20. }
  21. @override
  22. bool shouldRebuild(CustomSliverPersistentHeaderDelegate oldDelegate) {
  23. return maxHeight != oldDelegate.maxHeight || minHeight != oldDelegate.minHeight || child != oldDelegate.child;
  24. }
  25. }