Skip to content

Commit

Permalink
Added customBuilder (#16)
Browse files Browse the repository at this point in the history
* CI/CD: create CI/CD file for flutter analyzing and pana check (#13)

* Readme fixes, resolve 1 issue from codefactor (#14)

* Add custom builder (#15)

* chore: pipelines fixes (#17)

---------

Co-authored-by: Nastya Kirzner <94079414+kirznernasta@users.noreply.github.com>
Co-authored-by: Kiryl Ivonchyk <32823028+KirillSergeevich@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 5, 2023
1 parent b0571aa commit 2503f2e
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 40 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/wtf_sliding_sheet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: WTF Sliding Sheet CI/CD

on:
push:
branches:
pull_request:
branches:

jobs:
analyze:
name: Analyze and pana check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'

- name: Analyzing
run: flutter analyze

- name: Pana check
run: |
dart pub global activate pana
pana --exit-code-threshold 10 --no-warning
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## 1.1.0
* **Added** `customBuilder` [#15](https://github.com/What-the-Flutter/wtf_sliding_sheet/pull/15)

## 1.0.0
* **Fixed** [#7](https://github.com/flutterwtf/wtf_sliding_sheet/pull/7)
* **Added** flutter 3.10 support
* **Added** dart 3 support
* **Fixed** [#7](https://github.com/What-the-Flutter/wtf_sliding_sheet/pull/7)
* **Added** Flutter 3.10 support
* **Added** Dart 3 support

## 0.6.1
* **Migrate** to a new repository name
Expand Down Expand Up @@ -48,4 +51,4 @@
* **Changed** the implemenation for bottom sheets.

## 0.1.0
* Initial release
* Initial release
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Sliding Sheet

<p align="center">
<a href="https://flutter.wtf/">
<img alt="What the Flutter" src="https://static.tildacdn.com/tild6330-3461-4139-a163-666435336663/Group_13.svg" height=140/>
</a>
</p>

<p align="center">
<h3 align="center">Crafted with passion by
<a href="https://flutter.wtf/">
What the Flutter
</a> 🦜
</h3>
</p>

<p align="center">
<a href="https://pub.dev/packages/wtf_sliding_sheet">
<img alt="Pub" src="https://img.shields.io/pub/v/wtf_sliding_sheet?color=orange" />
</a>
<a href="https://github.com/What-the-Flutter/wtf_sliding_sheet/actions/workflows/wtf_sliding_sheet.yml">
<img alt="Build Status" src="https://github.com/What-the-Flutter/wtf_sliding_sheet/actions/workflows/wtf_sliding_sheet.yml/badge.svg"/>
</a>
<a href="https://www.codefactor.io/repository/github/what-the-flutter/wtf_sliding_sheet/overview/master">
<img alt="CodeFactor" src="https://www.codefactor.io/repository/github/what-the-flutter/wtf_sliding_sheet/badge/master"/>
</a>
</p>

---

A widget that can be dragged and scrolled in a single gesture and snapped to a list of extents.

<a href="https://github.com/What-the-Flutter/wtf_sliding_sheet/blob/master/example/lib/main.dart">
Expand All @@ -16,7 +44,7 @@ Add it to your `pubspec.yaml` file:

```yaml
dependencies:
wtf_sliding_sheet: ^1.0.0
wtf_sliding_sheet: ^1.1.0
```
Install packages from the command line
Expand Down Expand Up @@ -280,3 +308,20 @@ return SheetListenerBuilder(
The [example](https://github.com/What-the-Flutter/wtf_sliding_sheet/blob/master/example/lib/main.dart) for instance decreases the corner radius of the `SlidingSheet` as it gets dragged to the top and increases the headers top padding by the status bar height. Also, when content gets scrolled under the header it elevates.

Because these are common Material behaviors, `SlidingSheet` supports those out of the box, which can be achieved by setting the `avoidStatusBar` field to `true`, `cornerRadiusOnFullscreen` to `0` and `liftOnScrollHeaderElevation` to the elevation.

### Use cases

**Scrollable content**

![lifely_stories_bottom_sheet](https://github.com/What-the-Flutter/wtf_sliding_sheet/assets/94079414/67c4d178-02a5-4a3c-a447-6baadd1d144c)

The GIF above showcases the user experience when dealing with scrollable content. With our package, you can easily implement a smooth and intuitive sliding sheet that seamlessly integrates with your application.

---

**Confirmation sheet**

![lifely_confimation_sheet](https://github.com/What-the-Flutter/wtf_sliding_sheet/assets/94079414/bdf1865b-73f2-4f80-a82b-4abe82a3705f)

One of the simplest use cases is implementing easy confirmations within your application. The GIF above demonstrates it in action. With our package, you can effortlessly implement a sliding sheet that provides a smooth and intuitive confirmation experience.
Whether it's deleting a file, confirming a purchase, or accepting a prompt, the sliding sheet offers a straightforward and user-friendly approach.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package com.example.example

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
class MainActivity: FlutterActivity();
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class _ExampleState extends State<Example> {
isDismissable: isDismissable,
dismissOnBackdropTap: true,
isBackdropInteractable: true,
onDismissPrevented: (backButton, backDrop) async {
onDismissPrevented: ({required backButton, required backDrop}) async {
HapticFeedback.heavyImpact();

if (backButton || backDrop) {
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ packages:
dependency: "direct main"
description:
name: wtf_sliding_sheet
sha256: "518772ea0fb602c7e59a84b0ac8269d8e53a3abd0c7a650ca3fe85090aa13578"
sha256: "363386c648af7be498b017f77d8bf5abdf3c502e5ab8943391835ea1549ce122"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "1.0.0"
sdks:
dart: ">=3.0.0-0 <4.0.0"
flutter: ">=2.5.0"
3 changes: 1 addition & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ dependencies:
sdk: flutter

material_design_icons_flutter: ^6.0.7096

wtf_sliding_sheet: ^0.6.1
wtf_sliding_sheet: ^1.0.0

dev_dependencies:
flutter_lints: ^2.0.1
Expand Down
92 changes: 67 additions & 25 deletions lib/src/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ part 'sheet_controller.dart';
part 'sheet_dialog.dart';
part 'sheet_state.dart';

/// Widget for building sheet
/// Widget for building sheet.
typedef SheetBuilder = Widget Function(BuildContext context, SheetState state);

/// Callback for changing state of the sheet
/// Widget for building sheet with custom scroll view.
typedef CustomSheetBuilder = Widget Function(
BuildContext context,
ScrollController controller,
SheetState state,
);

/// Callback for changing state of the sheet.
typedef SheetListener = void Function(SheetState state);

/// Callback prevented dismiss the dialog
/// Callback prevented dismiss the dialog.
typedef OnDismissPreventedCallback = void Function(
{required bool backButton, required bool backDrop});

/// Callback for opening sheet
/// Callback for opening sheet.
typedef OnOpenCallback = void Function();

/// A widget that can be dragged and scrolled in a single gesture and snapped
Expand All @@ -37,7 +44,13 @@ class SlidingSheet extends StatefulWidget {
/// The builder for the main content of the sheet that will be scrolled if
/// the content is bigger than the height that the sheet can expand to.
/// {@endtemplate}
final SheetBuilder builder;
final SheetBuilder? builder;

/// {@template sliding_sheet.customBuilder}
/// Allows you to supply your own custom sroll view. Useful for infinite lists
/// that cannot be shrinkWrapped like long lists.
/// {@endtemplate}
final CustomSheetBuilder? customBuilder;

/// {@template sliding_sheet.headerBuilder}
/// The builder for a header that will be displayed at the top of the sheet
Expand Down Expand Up @@ -251,6 +264,11 @@ class SlidingSheet extends StatefulWidget {
/// The `builder` callback is used to build the main content of the sheet that
/// will be scrolled if the content is bigger than the height that the sheet can expand to.
///
/// The `customBuilder` callback is used to build such the main content like
/// infinite lists that cannot be shrinkWrapped.
///
/// Either the `builder` or the `customBuilder` must be specified.
///
/// The `headerBuilder` and `footerBuilder` can be used to build persistent widget on top
/// and bottom respectively, that wont be scrolled but will delegate the interactions on
/// them to the sheet.
Expand All @@ -275,7 +293,8 @@ class SlidingSheet extends StatefulWidget {
/// width is bigger than the `maxWidth` of the sheet.
SlidingSheet({
Key? key,
required SheetBuilder builder,
SheetBuilder? builder,
CustomSheetBuilder? customBuilder,
SheetBuilder? headerBuilder,
SheetBuilder? footerBuilder,
SnapSpec snapSpec = const SnapSpec(),
Expand Down Expand Up @@ -310,6 +329,7 @@ class SlidingSheet extends StatefulWidget {
}) : this._(
key: key,
builder: builder,
customBuilder: customBuilder,
headerBuilder: headerBuilder,
footerBuilder: footerBuilder,
snapSpec: snapSpec,
Expand Down Expand Up @@ -346,6 +366,7 @@ class SlidingSheet extends StatefulWidget {
SlidingSheet._({
Key? key,
required this.builder,
required this.customBuilder,
required this.headerBuilder,
required this.footerBuilder,
required this.snapSpec,
Expand Down Expand Up @@ -379,7 +400,12 @@ class SlidingSheet extends StatefulWidget {
this.isDismissable = true,
this.onDismissPrevented,
this.onOpen,
}) : assert(
}) :

/// Checking whether one of the `builder` and `customBuilder` is specified.
assert(builder != null || customBuilder != null),
assert(builder == null || customBuilder == null),
assert(
snapSpec.snappings.length >= 2,
'There must be at least two snapping extents to snap in between.',
),
Expand Down Expand Up @@ -427,8 +453,10 @@ class _SlidingSheetState extends State<SlidingSheet>
SheetController? sheetController;
late _SlidingSheetScrollController controller;

bool get isCustom => widget.customBuilder != null;

// Whether the sheet has drawn its first frame.
bool get isLaidOut => availableHeight > 0 && childHeight > 0;
bool isLaidOut = false;

// The total height of all sheet components.
double get sheetHeight =>
Expand Down Expand Up @@ -622,6 +650,8 @@ class _SlidingSheetState extends State<SlidingSheet>
final prevFooterHeight = footerHeight;
footerHeight = isFooterLaidOut ? footer!.size.height : 0;

isLaidOut = true;

if (mounted &&
(childHeight != prevChildHeight ||
headerHeight != prevHeaderHeight ||
Expand All @@ -644,8 +674,15 @@ class _SlidingSheetState extends State<SlidingSheet>
}

if (availableHeight > 0) {
final num maxPossibleExtent =
isLaidOut ? (sheetHeight / availableHeight).clamp(0.0, 1.0) : 1.0;
final num maxPossibleExtent = () {
if (isCustom) {
return 1.0;
} else {
return isLaidOut
? (sheetHeight / availableHeight).clamp(0.0, 1.0)
: 1.0;
}
}();

double extent = snap;
switch (snapPositioning) {
Expand Down Expand Up @@ -1052,21 +1089,26 @@ class _SlidingSheetState extends State<SlidingSheet>
Widget _buildScrollView() {
Widget scrollView = Listener(
onPointerUp: (_) => _handleNonDismissableSnapBack(),
child: SingleChildScrollView(
controller: controller,
physics: scrollSpec.physics,
padding: EdgeInsets.only(
top: !hasHeader ? padding.top : 0.0,
bottom: !hasFooter ? padding.bottom : 0.0,
),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: widget.minHeight ?? 0.0),
child: SizeChangedLayoutNotifier(
key: childKey,
child: widget.builder(context, state),
),
),
),
child: widget.customBuilder != null
? Container(
key: childKey,
child: widget.customBuilder!(context, controller, state),
)
: SingleChildScrollView(
controller: controller,
physics: scrollSpec.physics,
padding: EdgeInsets.only(
top: !hasHeader ? padding.top : 0.0,
bottom: !hasFooter ? padding.bottom : 0.0,
),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: widget.minHeight ?? 0.0),
child: SizeChangedLayoutNotifier(
key: childKey,
child: widget.builder!(context, state),
),
),
),
);

if (scrollSpec.showScrollbar) {
Expand Down
9 changes: 7 additions & 2 deletions lib/src/sheet_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Future<T?> showSlidingBottomSheet<T>(
cornerRadiusOnFullscreen: dialog.cornerRadiusOnFullscreen,
closeOnBackdropTap: dialog.dismissOnBackdropTap,
builder: dialog.builder,
customBuilder: dialog.customBuilder,
headerBuilder: dialog.headerBuilder,
footerBuilder: dialog.footerBuilder,
listener: dialog.listener,
Expand Down Expand Up @@ -114,7 +115,10 @@ Future<T?> showSlidingBottomSheet<T>(
/// A wrapper class to show a [SlidingSheet] as a bottom sheet dialog.
class SlidingSheetDialog {
/// {@macro sliding_sheet.builder}
final SheetBuilder builder;
final SheetBuilder? builder;

/// {@macro sliding_sheet.customBuilder}
final CustomSheetBuilder? customBuilder;

/// {@macro sliding_sheet.headerBuilder}
final SheetBuilder? headerBuilder;
Expand Down Expand Up @@ -200,7 +204,8 @@ class SlidingSheetDialog {

/// Creates a wrapper class to show a [SlidingSheet] as a bottom sheet dialog.
const SlidingSheetDialog({
required this.builder,
this.builder,
this.customBuilder,
this.headerBuilder,
this.footerBuilder,
this.snapSpec = const SnapSpec(),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wtf_sliding_sheet
description: A widget that can be dragged and scrolled in a single gesture and snapped to a list of extents.
version: 1.0.0
version: 1.1.0
homepage: https://pub.dev/packages/wtf_sliding_sheet
repository: https://github.com/What-the-Flutter/wtf_sliding_sheet

Expand Down

0 comments on commit 2503f2e

Please sign in to comment.