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

Fix: PopScope not working with modals in Flutter 3.24+ #237

Merged
merged 10 commits into from
Aug 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion .fvmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"flutter": "3.22.3"
"flutter": "3.24.1"
}
1 change: 0 additions & 1 deletion .github/workflows/dry_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches: main
pull_request:
branches: main

jobs:
dry-publish:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.22.3"
"dart.flutterSdkPath": ".fvm/versions/3.24.1"
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.0-f324.0.9.4 Sep 1, 2024

**This version requires Flutter 3.24.0 or later.** See the [README](https://github.com/fujidaiti/smooth_sheets/edit/main/README.md#for-developers-using-flutter-324) for more details.

- Fix: PopScope not working with modals in Flutter 3.24+ (#237)

## 0.9.4 Aug 31, 2024

- Add `SwipeDismissSensitivity`, a way to customize sensitivity of swipe-to-dismiss action on modal sheet (#222)
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@

<br/>

**CAUTION🚨**
## For developers using Flutter 3.24+

This library is currently in the experimental stage. The API may undergo changes without prior notice. For documentation of the latest published version, please visit the [package site](https://pub.dev/packages/smooth_sheets) on pub.dev.
If your project uses Flutter 3.24.0 or later, we recommend using the pre-release versions named `1.0.0-f324.x.x.x`. While you can still use the non-pre-release versions (e.g., `0.9.4`) with Flutter 3.24+, you may encounter issues related to the `PopScope` widget due to a breaking change in Flutter 3.24. There are no functional or API differences between the pre-release and non-pre-release versions, except that the pre-release versions require Flutter 3.24.0 or later.

```yaml
dependencies:
# For projects that uses the pre-release versions (requires Flutter 3.24+)
smooth_sheets: ^1.0.0-f324.0.9.4
# For projects that uses the non-pre-release versions
smooth_sheets: ^0.9.4
```

<details>
<summary>Background</summary>

This package previously used the `Route.onPopInvoked` method to invoke `PopScope.onPopInvoked` callbacks when users performed a swipe-to-dismiss gesture. However, these methods were deprecated in Flutter 3.24.0 as part of a [breaking change](https://docs.flutter.dev/release/breaking-changes/popscope-with-result) related to the `PopScope` widget. The problem is that `ModalRoute.onPopInvoked`, which was an override of `Route.onPopInvoked` and where `PopScope.onPopInvoked` callbacks were actually invoked, was removed. As a result, the `PopScope.onPopInvoked` callback is no longer invoked in Flutter 3.24+. These changes led to issues such as [#233](https://github.com/fujidaiti/smooth_sheets/issues/233).

The only possible solution was to replace `Route.onPopInvoked` with `Route.onPopInvokedWithResult`, which was introduced in Flutter 3.24.0. However, migrating to the new API would require increasing the lower bound of the SDK constraint to 3.24.0. For those using an SDK version lower than 3.24, this change would be a significant breaking change. Ultimately, we decided to publish different versions for different SDK constraints to maintain backward compatibility.
</details>

<br/>

Expand Down
2 changes: 1 addition & 1 deletion example/lib/showcase/ai_playlist_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _SheetShell extends StatelessWidget {
bottom: false,
child: PopScope(
canPop: false,
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, _) async {
if (!didPop) {
final shouldPop = await showCancelDialog() ?? false;
if (shouldPop && context.mounted) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/declarative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _ExampleSheet extends StatelessWidget {
// the system back gestures and tapping on the barrier, all in one place.
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, _) async {
if (!didPop) {
final shouldPop = await showConfirmationDialog(context);
if (shouldPop == true && context.mounted) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/imperative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _ExampleSheet extends StatelessWidget {
// the system back gestures and tapping on the barrier, all in one place.
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, _) async {
if (!didPop) {
final shouldPop = await showConfirmationDialog(context);
if (shouldPop == true && context.mounted) {
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -164,18 +164,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.15.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -240,10 +240,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.7.2"
typed_data:
dependency: transitive
description:
Expand All @@ -264,10 +264,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "14.2.5"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.24.0"
2 changes: 1 addition & 1 deletion lib/smooth_sheets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Comprehensive bottom sheet library supporting imperative and declarative
/// navigation APIs, nested navigation, persistent and modal styles (including
/// the iOS flavor), and more.
library smooth_sheets;
library;

export 'src/draggable/draggable.dart';
export 'src/foundation/foundation.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/modal/modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class _SwipeDismissibleController with SheetGestureTamperer {
}

if (invokePop) {
route.onPopInvoked(didPop);
route.onPopInvokedWithResult(didPop, null);
}

return true;
Expand Down
1 change: 1 addition & 0 deletions lib/src/scrollable/sheet_content_scroll_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SheetContentScrollPosition extends ScrollPositionWithSingleContext {

/// Whether the scroll view should prevent its contents from receiving
/// pointer events.
@override
bool get shouldIgnorePointer => activity!.shouldIgnorePointer;

/// Sets the user scroll direction.
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: smooth_sheets
description: Sheet widgets with smooth motion and great flexibility. Also supports nested navigation in both imperative and declarative ways.
version: 0.9.4
version: 1.0.0-f324.0.9.4
repository: https://github.com/fujidaiti/smooth_sheets
screenshots:
- description: Practical examples of smooth_sheets.
Expand All @@ -11,8 +11,8 @@ topics:
- bottom-sheet

environment:
sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"
sdk: ">=3.5.0 <4.0.0"
flutter: ">=3.24.0"

dependencies:
collection: ^1.17.1
Expand Down
Loading