diff --git a/README.md b/README.md index 6bd614d..2abcec9 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Widget _buildBottomSheet( ![Demo](https://raw.githubusercontent.com/surfstudio/flutter-bottom-sheet/main/assets/open-sticky-bottom-sheet.gif) To show sticky BottomSheet, use: -**You have to return SliverChildListDelegate from builder !!!** +**You have to return SliverMultiBoxAdaptorWidget from builder (SliverList, SliverGrid or SliverFixedExtentList) !!!** ```dart showStickyFlexibleBottomSheet( @@ -121,10 +121,17 @@ showStickyFlexibleBottomSheet( ); }, builder: (BuildContext context, double offset) { - return SliverChildListDelegate( - [...], + return SliverList( + delegate: SliverChildBuilderDelegate( + childCount: 5, + (BuildContext context, int index) { + return ....; + }, + ), ); }, + + anchors: [0, 0.5, 1], ); ``` @@ -146,7 +153,7 @@ All notable changes to this project will be documented in [this file](./CHANGELO ## Issues -To report your issues, submit them directly in the [Issues](https://github.com/surfstudio/flutter-bottom-sheet/issues) section. +To report your issues, submit them directly in the [Issues](https://github.com/surfstudio/flutter-bottom-sheet/issues) section. ## Contribute diff --git a/example/lib/standard_bottom_sheet_example.dart b/example/lib/standard_bottom_sheet_example.dart index 2c2dd89..7c74042 100644 --- a/example/lib/standard_bottom_sheet_example.dart +++ b/example/lib/standard_bottom_sheet_example.dart @@ -97,8 +97,10 @@ class _StandardBottomSheetExampleState ); }, bodyBuilder: (context, offset) { - return SliverChildListDelegate( - _children, + return SliverList( + delegate: SliverChildListDelegate( + _children, + ), ); }, anchors: [0.2, 0.5, 0.8], diff --git a/lib/src/flexible_bottom_sheet.dart b/lib/src/flexible_bottom_sheet.dart index 7a5a6fd..950246c 100644 --- a/lib/src/flexible_bottom_sheet.dart +++ b/lib/src/flexible_bottom_sheet.dart @@ -46,8 +46,8 @@ typedef FlexibleDraggableScrollableHeaderWidgetBuilder = Widget Function( /// and [bottomSheetOffset] for determining the position of the BottomSheet /// relative to the upper border of the screen. /// [bottomSheetOffset] - fractional value of offset. -typedef FlexibleDraggableScrollableWidgetBodyBuilder = SliverChildDelegate - Function( +typedef FlexibleDraggableScrollableWidgetBodyBuilder + = SliverMultiBoxAdaptorWidget Function( BuildContext context, double bottomSheetOffset, ); @@ -98,6 +98,7 @@ class FlexibleBottomSheet extends StatefulWidget { final FlexibleDraggableScrollableWidgetBuilder? builder; final FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder; final FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder; + final EdgeInsets? bodyPadding; final bool isCollapsible; final bool isExpand; final DraggableScrollableController? draggableScrollableController; @@ -122,6 +123,7 @@ class FlexibleBottomSheet extends StatefulWidget { this.builder, this.headerBuilder, this.bodyBuilder, + this.bodyPadding, this.isCollapsible = false, this.isExpand = true, this.animationController, @@ -152,6 +154,7 @@ class FlexibleBottomSheet extends StatefulWidget { FlexibleDraggableScrollableWidgetBuilder? builder, FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder, FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder, + EdgeInsets? bodyPadding, bool isExpand = true, AnimationController? animationController, List? anchors, @@ -170,6 +173,7 @@ class FlexibleBottomSheet extends StatefulWidget { builder: builder, headerBuilder: headerBuilder, bodyBuilder: bodyBuilder, + bodyPadding: bodyPadding, minHeight: 0, initHeight: initHeight, isCollapsible: true, @@ -395,6 +399,7 @@ class _FlexibleBottomSheetState extends State> { builder: widget.builder, decoration: contentDecoration, bodyBuilder: widget.bodyBuilder, + bodyPadding: widget.bodyPadding, headerBuilder: widget.headerBuilder, minHeaderHeight: widget.minHeaderHeight, maxHeaderHeight: widget.maxHeaderHeight, @@ -468,6 +473,7 @@ class _Content extends StatefulWidget { final Decoration? decoration; final FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder; final FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder; + final EdgeInsets? bodyPadding; final double? minHeaderHeight; final double? maxHeaderHeight; final double currentExtent; @@ -483,6 +489,7 @@ class _Content extends StatefulWidget { this.decoration, this.headerBuilder, this.bodyBuilder, + this.bodyPadding, this.minHeaderHeight, this.maxHeaderHeight, this.getContentHeight, @@ -528,6 +535,9 @@ class _ContentState extends State<_Content> { ); } + final bodyBuilder = widget.bodyBuilder; + final bodyPadding = widget.bodyPadding; + return Material( type: MaterialType.transparency, child: DecoratedBox( @@ -546,13 +556,19 @@ class _ContentState extends State<_Content> { child: widget.headerBuilder!(context, widget.currentExtent), ), ), - if (widget.bodyBuilder != null) - SliverList( - delegate: widget.bodyBuilder!( - context, - widget.currentExtent, - ), - ), + if (bodyBuilder != null) + bodyPadding != null + ? SliverPadding( + padding: bodyPadding, + sliver: bodyBuilder( + context, + widget.currentExtent, + ), + ) + : bodyBuilder( + context, + widget.currentExtent, + ), ], ), ), diff --git a/lib/src/flexible_bottom_sheet_route.dart b/lib/src/flexible_bottom_sheet_route.dart index 4fb28a7..366ab10 100644 --- a/lib/src/flexible_bottom_sheet_route.dart +++ b/lib/src/flexible_bottom_sheet_route.dart @@ -101,6 +101,7 @@ Future showFlexibleBottomSheet({ /// even without a list. /// /// [bodyBuilder] - content's builder. +/// [bodyPadding] padding for content's builder. /// [draggableScrollableController] that allow programmatically control bottom sheet. /// [minHeight] - min height in fractional value for bottom sheet. e.g. 0.1. /// [initHeight] - init height in fractional value for bottom sheet. e.g. 0.5. @@ -132,6 +133,7 @@ Future showStickyFlexibleBottomSheet({ required BuildContext context, required FlexibleDraggableScrollableHeaderWidgetBuilder headerBuilder, required FlexibleDraggableScrollableWidgetBodyBuilder bodyBuilder, + EdgeInsets? bodyPadding, DraggableScrollableController? draggableScrollableController, double? minHeight, double? initHeight, @@ -171,6 +173,7 @@ Future showStickyFlexibleBottomSheet({ draggableScrollableController: draggableScrollableController, isExpand: isExpand, bodyBuilder: bodyBuilder, + bodyPadding: bodyPadding, headerBuilder: headerBuilder, isModal: isModal, anchors: anchors, @@ -193,6 +196,7 @@ class FlexibleBottomSheetRoute extends PopupRoute { final FlexibleDraggableScrollableWidgetBuilder? builder; final FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder; final FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder; + final EdgeInsets? bodyPadding; final DraggableScrollableController? draggableScrollableController; final double minHeight; final double initHeight; @@ -244,6 +248,7 @@ class FlexibleBottomSheetRoute extends PopupRoute { this.builder, this.headerBuilder, this.bodyBuilder, + this.bodyPadding, this.theme, this.barrierLabel, this.anchors, @@ -287,6 +292,7 @@ class FlexibleBottomSheetRoute extends PopupRoute { builder: builder, headerBuilder: headerBuilder, bodyBuilder: bodyBuilder, + bodyPadding: bodyPadding, isExpand: isExpand, animationController: _animationController, anchors: anchors, @@ -307,6 +313,7 @@ class FlexibleBottomSheetRoute extends PopupRoute { builder: builder, headerBuilder: headerBuilder, bodyBuilder: bodyBuilder, + bodyPadding: bodyPadding, isExpand: isExpand, animationController: _animationController, draggableScrollableController: draggableScrollableController, diff --git a/test/sticky_bottom_sheet_test.dart b/test/sticky_bottom_sheet_test.dart index bd61563..951f0cf 100644 --- a/test/sticky_bottom_sheet_test.dart +++ b/test/sticky_bottom_sheet_test.dart @@ -62,8 +62,10 @@ void main() { ); }, bodyBuilder: (context, offset) { - return SliverChildListDelegate( - _listWidgets, + return SliverList( + delegate: SliverChildListDelegate( + _listWidgets, + ), ); }, );