Skip to content

Commit

Permalink
[0.6.2] Max extend: fix current extend after sheet size changed (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirznernasta authored May 10, 2023
1 parent 0edc581 commit 4cd2e0b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.2
* **Fixed** [#7](https://github.com/flutterwtf/wtf_sliding_sheet/pull/7)

## 0.6.1
* **Migrate** to a new repository name

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add it to your `pubspec.yaml` file:

```yaml
dependencies:
wtf_sliding_sheet: ^0.6.1
wtf_sliding_sheet: ^0.6.2
```
Install packages from the command line
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.6.1"
version: "0.6.2"
sdks:
dart: ">=2.19.0 <3.0.0"
flutter: ">=2.5.0"
17 changes: 11 additions & 6 deletions lib/src/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import 'specs.dart';
import 'util.dart';

part 'scrolling.dart';

part 'sheet_controller.dart';

part 'sheet_dialog.dart';

part 'sheet_state.dart';

/// Widget for building sheet
Expand Down Expand Up @@ -610,6 +607,9 @@ class _SlidingSheetState extends State<SlidingSheet>
final RenderBox? footer =
footerKey.currentContext?.findRenderObject() as RenderBox?;

final previousMaxExtent =
isLaidOut ? (sheetHeight / availableHeight).clamp(0.0, 1.0) : 1.0;

final isChildLaidOut = child?.hasSize == true;
final prevChildHeight = childHeight;
childHeight = isChildLaidOut ? child!.size.height : 0;
Expand All @@ -626,7 +626,7 @@ class _SlidingSheetState extends State<SlidingSheet>
(childHeight != prevChildHeight ||
headerHeight != prevHeaderHeight ||
footerHeight != prevFooterHeight)) {
_updateSnappingsAndExtent();
_updateSnappingsAndExtent(previousMaxExtent: previousMaxExtent);
setState(() {});
}
});
Expand Down Expand Up @@ -703,7 +703,7 @@ class _SlidingSheetState extends State<SlidingSheet>
}
}

void _updateSnappingsAndExtent() {
void _updateSnappingsAndExtent({num? previousMaxExtent}) {
snappings = snapSpec.snappings.map(_normalizeSnap).toList()..sort();

if (extent != null) {
Expand All @@ -717,7 +717,12 @@ class _SlidingSheetState extends State<SlidingSheet>
..maxExtent = maxExtent
..minExtent = minExtent;

if (currentExtent > maxExtent) currentExtent = maxExtent;
final isCurrentPreviousMaxExtent = previousMaxExtent != null &&
(currentExtent - previousMaxExtent).abs() < 0.01;

if (currentExtent > maxExtent || isCurrentPreviousMaxExtent) {
currentExtent = maxExtent;
}
}
}

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: 0.6.1
version: 0.6.2
homepage: https://pub.dev/packages/wtf_sliding_sheet
repository: https://github.com/flutterwtf/wtf_sliding_sheet

Expand Down

0 comments on commit 4cd2e0b

Please sign in to comment.