From 5a30ef7931c6a33872e0bf894630c821a4f5552b Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Wed, 17 Jul 2024 11:34:03 +0300 Subject: [PATCH 1/3] add SliverMultiBoxAdaptorWidget instead of SliverChildDelegate --- example/lib/standard_bottom_sheet_example.dart | 6 ++++-- lib/src/flexible_bottom_sheet.dart | 12 +++++------- test/sticky_bottom_sheet_test.dart | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) 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..6de474b 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, ); @@ -547,11 +547,9 @@ class _ContentState extends State<_Content> { ), ), if (widget.bodyBuilder != null) - SliverList( - delegate: widget.bodyBuilder!( - context, - widget.currentExtent, - ), + widget.bodyBuilder!( + context, + widget.currentExtent, ), ], ), 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, + ), ); }, ); From 98db6d992e5377b0ba23f75be0b63e0b78f0e2c7 Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Wed, 17 Jul 2024 13:33:39 +0300 Subject: [PATCH 2/3] add bodyBuilder sliver padding --- lib/src/flexible_bottom_sheet.dart | 28 +++++++++++++++++++----- lib/src/flexible_bottom_sheet_route.dart | 7 ++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/src/flexible_bottom_sheet.dart b/lib/src/flexible_bottom_sheet.dart index 6de474b..950246c 100644 --- a/lib/src/flexible_bottom_sheet.dart +++ b/lib/src/flexible_bottom_sheet.dart @@ -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,11 +556,19 @@ class _ContentState extends State<_Content> { child: widget.headerBuilder!(context, widget.currentExtent), ), ), - if (widget.bodyBuilder != null) - 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, From 424cc337e9345731dba529bd52189b656e3f8597 Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Fri, 19 Jul 2024 11:52:26 +0300 Subject: [PATCH 3/3] update README.md --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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