Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Slivers with Multiple Box Children #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -121,10 +121,17 @@ showStickyFlexibleBottomSheet(
);
},
builder: (BuildContext context, double offset) {
return SliverChildListDelegate(
<Widget>[...],
return SliverList(
delegate: SliverChildBuilderDelegate(
childCount: 5,
(BuildContext context, int index) {
return <Widget>....;
},
),
);
},


anchors: [0, 0.5, 1],
);
```
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions example/lib/standard_bottom_sheet_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ class _StandardBottomSheetExampleState
);
},
bodyBuilder: (context, offset) {
return SliverChildListDelegate(
_children,
return SliverList(
delegate: SliverChildListDelegate(
_children,
),
);
},
anchors: [0.2, 0.5, 0.8],
Expand Down
34 changes: 25 additions & 9 deletions lib/src/flexible_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -98,6 +98,7 @@ class FlexibleBottomSheet<T> extends StatefulWidget {
final FlexibleDraggableScrollableWidgetBuilder? builder;
final FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder;
final FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder;
final EdgeInsets? bodyPadding;
final bool isCollapsible;
final bool isExpand;
final DraggableScrollableController? draggableScrollableController;
Expand All @@ -122,6 +123,7 @@ class FlexibleBottomSheet<T> extends StatefulWidget {
this.builder,
this.headerBuilder,
this.bodyBuilder,
this.bodyPadding,
this.isCollapsible = false,
this.isExpand = true,
this.animationController,
Expand Down Expand Up @@ -152,6 +154,7 @@ class FlexibleBottomSheet<T> extends StatefulWidget {
FlexibleDraggableScrollableWidgetBuilder? builder,
FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder,
FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder,
EdgeInsets? bodyPadding,
bool isExpand = true,
AnimationController? animationController,
List<double>? anchors,
Expand All @@ -170,6 +173,7 @@ class FlexibleBottomSheet<T> extends StatefulWidget {
builder: builder,
headerBuilder: headerBuilder,
bodyBuilder: bodyBuilder,
bodyPadding: bodyPadding,
minHeight: 0,
initHeight: initHeight,
isCollapsible: true,
Expand Down Expand Up @@ -395,6 +399,7 @@ class _FlexibleBottomSheetState<T> extends State<FlexibleBottomSheet<T>> {
builder: widget.builder,
decoration: contentDecoration,
bodyBuilder: widget.bodyBuilder,
bodyPadding: widget.bodyPadding,
headerBuilder: widget.headerBuilder,
minHeaderHeight: widget.minHeaderHeight,
maxHeaderHeight: widget.maxHeaderHeight,
Expand Down Expand Up @@ -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;
Expand All @@ -483,6 +489,7 @@ class _Content extends StatefulWidget {
this.decoration,
this.headerBuilder,
this.bodyBuilder,
this.bodyPadding,
this.minHeaderHeight,
this.maxHeaderHeight,
this.getContentHeight,
Expand Down Expand Up @@ -528,6 +535,9 @@ class _ContentState extends State<_Content> {
);
}

final bodyBuilder = widget.bodyBuilder;
final bodyPadding = widget.bodyPadding;

return Material(
type: MaterialType.transparency,
child: DecoratedBox(
Expand All @@ -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,
),
],
),
),
Expand Down
7 changes: 7 additions & 0 deletions lib/src/flexible_bottom_sheet_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Future<T?> showFlexibleBottomSheet<T>({
/// 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.
Expand Down Expand Up @@ -132,6 +133,7 @@ Future<T?> showStickyFlexibleBottomSheet<T>({
required BuildContext context,
required FlexibleDraggableScrollableHeaderWidgetBuilder headerBuilder,
required FlexibleDraggableScrollableWidgetBodyBuilder bodyBuilder,
EdgeInsets? bodyPadding,
DraggableScrollableController? draggableScrollableController,
double? minHeight,
double? initHeight,
Expand Down Expand Up @@ -171,6 +173,7 @@ Future<T?> showStickyFlexibleBottomSheet<T>({
draggableScrollableController: draggableScrollableController,
isExpand: isExpand,
bodyBuilder: bodyBuilder,
bodyPadding: bodyPadding,
headerBuilder: headerBuilder,
isModal: isModal,
anchors: anchors,
Expand All @@ -193,6 +196,7 @@ class FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
final FlexibleDraggableScrollableWidgetBuilder? builder;
final FlexibleDraggableScrollableHeaderWidgetBuilder? headerBuilder;
final FlexibleDraggableScrollableWidgetBodyBuilder? bodyBuilder;
final EdgeInsets? bodyPadding;
final DraggableScrollableController? draggableScrollableController;
final double minHeight;
final double initHeight;
Expand Down Expand Up @@ -244,6 +248,7 @@ class FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
this.builder,
this.headerBuilder,
this.bodyBuilder,
this.bodyPadding,
this.theme,
this.barrierLabel,
this.anchors,
Expand Down Expand Up @@ -287,6 +292,7 @@ class FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
builder: builder,
headerBuilder: headerBuilder,
bodyBuilder: bodyBuilder,
bodyPadding: bodyPadding,
isExpand: isExpand,
animationController: _animationController,
anchors: anchors,
Expand All @@ -307,6 +313,7 @@ class FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
builder: builder,
headerBuilder: headerBuilder,
bodyBuilder: bodyBuilder,
bodyPadding: bodyPadding,
isExpand: isExpand,
animationController: _animationController,
draggableScrollableController: draggableScrollableController,
Expand Down
6 changes: 4 additions & 2 deletions test/sticky_bottom_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ void main() {
);
},
bodyBuilder: (context, offset) {
return SliverChildListDelegate(
_listWidgets,
return SliverList(
delegate: SliverChildListDelegate(
_listWidgets,
),
);
},
);
Expand Down