From e28c3bc18ab14d4ea713894dbb40de4b723ade4a Mon Sep 17 00:00:00 2001 From: Jaime Blasco Date: Mon, 18 Nov 2024 19:29:35 +0100 Subject: [PATCH] feat: pop scope --- modal_bottom_sheet/README.md | 2 +- .../ios/Flutter/AppFrameworkInfo.plist | 2 +- modal_bottom_sheet/example/ios/Podfile | 2 +- modal_bottom_sheet/example/ios/Podfile.lock | 6 +- .../ios/Runner.xcodeproj/project.pbxproj | 8 +-- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- modal_bottom_sheet/example/lib/main.dart | 5 +- .../example/lib/modals/modal_complex_all.dart | 52 +++++++------- .../example/lib/modals/modal_will_scope.dart | 51 +++++++------- modal_bottom_sheet/example/pubspec.lock | 52 ++++++++++---- .../lib/src/bottom_sheet_route.dart | 17 ++++- .../ios/Flutter/AppFrameworkInfo.plist | 2 +- .../ios/Runner.xcodeproj/project.pbxproj | 8 +-- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../route/examples/modal_complex_all.dart | 51 +++++++------- .../route/examples/modal_fit_will_scope.dart | 14 ++-- .../route/examples/modal_will_scope.dart | 52 +++++++------- .../lib/examples/sheet/fold_screen_sheet.dart | 2 +- .../sheet/sheet_without_momentum.dart | 2 +- .../lib/examples/sheet/snap_sheet.dart | 2 +- .../lib/examples/sheet/text_field.dart | 2 +- sheet/example/lib/route_example_page.dart | 8 +-- sheet/example/pubspec.lock | 68 +++++++++++++------ sheet/example/pubspec.yaml | 2 +- sheet/lib/src/route/sheet_route.dart | 35 ++++++---- 25 files changed, 260 insertions(+), 189 deletions(-) diff --git a/modal_bottom_sheet/README.md b/modal_bottom_sheet/README.md index 5b606e1b..a6ddec9e 100644 --- a/modal_bottom_sheet/README.md +++ b/modal_bottom_sheet/README.md @@ -20,7 +20,7 @@ Why not `showModalBottomSheet`? Inspired by `showModalBottomSheet`, it completes with some must-need features: - Support for inside scrollview + dragging down to close (`showModalBottomSheet` won't work correctly with scrollviews. -- Support for `WillPopScope` to prevent closing the dialog. +- Support for `PopScope` and `WillPopScope` to prevent closing the dialog. - Support for scroll to top when tapping status bar (iOS only) - Support for top SafeArea (not supported by showModalBottomSheet) - Cupertino modal bottom sheet diff --git a/modal_bottom_sheet/example/ios/Flutter/AppFrameworkInfo.plist b/modal_bottom_sheet/example/ios/Flutter/AppFrameworkInfo.plist index 9625e105..7c569640 100644 --- a/modal_bottom_sheet/example/ios/Flutter/AppFrameworkInfo.plist +++ b/modal_bottom_sheet/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/modal_bottom_sheet/example/ios/Podfile b/modal_bottom_sheet/example/ios/Podfile index 88359b22..279576f3 100644 --- a/modal_bottom_sheet/example/ios/Podfile +++ b/modal_bottom_sheet/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '11.0' +# platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/modal_bottom_sheet/example/ios/Podfile.lock b/modal_bottom_sheet/example/ios/Podfile.lock index 69a9e703..541635a1 100644 --- a/modal_bottom_sheet/example/ios/Podfile.lock +++ b/modal_bottom_sheet/example/ios/Podfile.lock @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 url_launcher_ios: 68d46cc9766d0c41dbdc884310529557e3cd7a86 -PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 +PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011 -COCOAPODS: 1.14.3 +COCOAPODS: 1.15.2 diff --git a/modal_bottom_sheet/example/ios/Runner.xcodeproj/project.pbxproj b/modal_bottom_sheet/example/ios/Runner.xcodeproj/project.pbxproj index 1418909a..add1a572 100644 --- a/modal_bottom_sheet/example/ios/Runner.xcodeproj/project.pbxproj +++ b/modal_bottom_sheet/example/ios/Runner.xcodeproj/project.pbxproj @@ -155,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -342,7 +342,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -420,7 +420,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -469,7 +469,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/modal_bottom_sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/modal_bottom_sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index b52b2e69..e67b2808 100644 --- a/modal_bottom_sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/modal_bottom_sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ { builder: (context) => ModalWithNavigator(), )), ListTile( - title: - Text('Cupertino Navigator + Scroll + WillPopScope'), + title: Text('Cupertino Navigator + Scroll + PopScope'), onTap: () => showCupertinoModalBottomSheet( expand: true, context: context, @@ -218,7 +217,7 @@ class _MyHomePageState extends State { ), ), ListTile( - title: Text('Modal with WillPopScope'), + title: Text('Modal with PopScope'), onTap: () => showCupertinoModalBottomSheet( expand: true, context: context, diff --git a/modal_bottom_sheet/example/lib/modals/modal_complex_all.dart b/modal_bottom_sheet/example/lib/modals/modal_complex_all.dart index 68508fde..2eaec2ab 100644 --- a/modal_bottom_sheet/example/lib/modals/modal_complex_all.dart +++ b/modal_bottom_sheet/example/lib/modals/modal_complex_all.dart @@ -8,31 +8,33 @@ class ComplexModal extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: WillPopScope( - onWillPop: () async { - bool shouldClose = true; - await showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: Text('Should Close?'), - actions: [ - CupertinoButton( - child: Text('Yes'), - onPressed: () { - shouldClose = true; - Navigator.of(context).pop(); - }, - ), - CupertinoButton( - child: Text('No'), - onPressed: () { - shouldClose = false; - Navigator.of(context).pop(); - }, - ), - ], - )); - return shouldClose; + child: PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (!didPop) { + final sheetNavigator = Navigator.of(context); + + showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: Text('Should Close?'), + actions: [ + CupertinoButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + sheetNavigator.pop(); + }, + ), + CupertinoButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + )); + } }, child: Navigator( onGenerateRoute: (_) => MaterialPageRoute( diff --git a/modal_bottom_sheet/example/lib/modals/modal_will_scope.dart b/modal_bottom_sheet/example/lib/modals/modal_will_scope.dart index 506f84c3..992023b0 100644 --- a/modal_bottom_sheet/example/lib/modals/modal_will_scope.dart +++ b/modal_bottom_sheet/example/lib/modals/modal_will_scope.dart @@ -7,31 +7,32 @@ class ModalWillScope extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: WillPopScope( - onWillPop: () async { - bool shouldClose = true; - await showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: Text('Should Close?'), - actions: [ - CupertinoButton( - child: Text('Yes'), - onPressed: () { - shouldClose = true; - Navigator.of(context).pop(); - }, - ), - CupertinoButton( - child: Text('No'), - onPressed: () { - shouldClose = false; - Navigator.of(context).pop(); - }, - ), - ], - )); - return shouldClose; + child: PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + final sheetNavigator = Navigator.of(context); + showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: Text('Should Close?'), + actions: [ + CupertinoButton( + child: Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + CupertinoButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + sheetNavigator.pop(); + }, + ), + ], + ), + ); }, child: CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( diff --git a/modal_bottom_sheet/example/pubspec.lock b/modal_bottom_sheet/example/pubspec.lock index 3eaf01df..60af5126 100644 --- a/modal_bottom_sheet/example/pubspec.lock +++ b/modal_bottom_sheet/example/pubspec.lock @@ -72,6 +72,30 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: "direct dev" description: @@ -84,41 +108,41 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" modal_bottom_sheet: dependency: "direct main" description: path: ".." relative: true source: path - version: "3.0.1" + version: "3.0.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" plugin_platform_interface: dependency: transitive description: @@ -252,14 +276,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "13.0.0" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.13.0" diff --git a/modal_bottom_sheet/lib/src/bottom_sheet_route.dart b/modal_bottom_sheet/lib/src/bottom_sheet_route.dart index c797ea54..967851ca 100644 --- a/modal_bottom_sheet/lib/src/bottom_sheet_route.dart +++ b/modal_bottom_sheet/lib/src/bottom_sheet_route.dart @@ -96,10 +96,21 @@ class _ModalBottomSheetState extends State<_ModalBottomSheet> { expanded: widget.route.expanded, containerBuilder: widget.route.containerBuilder, animationController: widget.route._animationController!, - shouldClose: widget.route._hasScopedWillPopCallback + shouldClose: widget.route.popDisposition == + RoutePopDisposition.doNotPop || + widget.route._hasScopedWillPopCallback ? () async { + // ignore: deprecated_member_use final willPop = await widget.route.willPop(); - return willPop != RoutePopDisposition.doNotPop; + final popDisposition = widget.route.popDisposition; + final shouldClose = + !(willPop == RoutePopDisposition.doNotPop || + popDisposition == RoutePopDisposition.doNotPop); + popDisposition == RoutePopDisposition.doNotPop; + if (!shouldClose) { + widget.route.onPopInvoked(false); + } + return shouldClose; } : null, onClosing: () { @@ -138,7 +149,7 @@ class ModalSheetRoute extends PageRoute { this.animationCurve, Duration? duration, super.settings, - }) : duration = duration ?? _bottomSheetDuration; + }) : duration = duration ?? _bottomSheetDuration; final double? closeProgressThreshold; final WidgetWithChildBuilder? containerBuilder; diff --git a/sheet/example/ios/Flutter/AppFrameworkInfo.plist b/sheet/example/ios/Flutter/AppFrameworkInfo.plist index 4f8d4d24..8c6e5614 100644 --- a/sheet/example/ios/Flutter/AppFrameworkInfo.plist +++ b/sheet/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/sheet/example/ios/Runner.xcodeproj/project.pbxproj b/sheet/example/ios/Runner.xcodeproj/project.pbxproj index 8036f6e3..ad590e39 100644 --- a/sheet/example/ios/Runner.xcodeproj/project.pbxproj +++ b/sheet/example/ios/Runner.xcodeproj/project.pbxproj @@ -127,7 +127,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -275,7 +275,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -361,7 +361,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -410,7 +410,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index b52b2e69..e67b2808 100644 --- a/sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/sheet/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ ( - context: context, - builder: (BuildContext context) => CupertinoAlertDialog( - title: const Text('Should Close?'), - actions: [ - CupertinoButton( - child: const Text('Yes'), - onPressed: () { - shouldClose = true; - Navigator.of(context).pop(); - }, - ), - CupertinoButton( - child: const Text('No'), - onPressed: () { - shouldClose = false; - Navigator.of(context).pop(); - }, - ), - ], - )); - return shouldClose; + child: PopScope( + canPop: false, + onPopInvoked: (didPop) { + final sheetNavigator = Navigator.of(context); + if (!didPop) { + showCupertinoDialog( + context: context, + builder: (BuildContext context) => CupertinoAlertDialog( + title: const Text('Should Close?'), + actions: [ + CupertinoButton( + child: const Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + sheetNavigator.pop(); + }, + ), + CupertinoButton( + child: const Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + )); + } }, child: Navigator( onGenerateRoute: (_) => MaterialPageRoute( diff --git a/sheet/example/lib/examples/route/examples/modal_fit_will_scope.dart b/sheet/example/lib/examples/route/examples/modal_fit_will_scope.dart index 6a226794..2d57104b 100644 --- a/sheet/example/lib/examples/route/examples/modal_fit_will_scope.dart +++ b/sheet/example/lib/examples/route/examples/modal_fit_will_scope.dart @@ -7,10 +7,12 @@ class ModalFitWillScope extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: WillPopScope( - onWillPop: () async { - bool shouldClose = true; - await showCupertinoDialog( + child: PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + final sheetNavigator = Navigator.of(context); + showCupertinoDialog( context: context, builder: (BuildContext context) => CupertinoAlertDialog( title: const Text('Should Close?'), @@ -18,20 +20,18 @@ class ModalFitWillScope extends StatelessWidget { CupertinoButton( child: const Text('Yes'), onPressed: () { - shouldClose = true; Navigator.of(context).pop(); + sheetNavigator.pop(); }, ), CupertinoButton( child: const Text('No'), onPressed: () { - shouldClose = false; Navigator.of(context).pop(); }, ), ], )); - return shouldClose; }, child: Column( mainAxisSize: MainAxisSize.min, diff --git a/sheet/example/lib/examples/route/examples/modal_will_scope.dart b/sheet/example/lib/examples/route/examples/modal_will_scope.dart index ae02e80f..49bbad7f 100644 --- a/sheet/example/lib/examples/route/examples/modal_will_scope.dart +++ b/sheet/example/lib/examples/route/examples/modal_will_scope.dart @@ -7,31 +7,35 @@ class ModalWillScope extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: WillPopScope( - onWillPop: () async { - bool shouldClose = true; - await showCupertinoDialog( + child: PopScope( + canPop: false, + onPopInvoked: (didPop) async { + if (didPop) { + return; + } + final sheetNavigator = Navigator.of(context); + showCupertinoDialog( context: context, - builder: (BuildContext context) => CupertinoAlertDialog( - title: const Text('Should Close?'), - actions: [ - CupertinoButton( - child: const Text('Yes'), - onPressed: () { - shouldClose = true; - Navigator.of(context).pop(); - }, - ), - CupertinoButton( - child: const Text('No'), - onPressed: () { - shouldClose = false; - Navigator.of(context).pop(); - }, - ), - ], - )); - return shouldClose; + builder: (BuildContext context) { + return CupertinoAlertDialog( + title: const Text('Should Close?'), + actions: [ + CupertinoButton( + child: const Text('Yes'), + onPressed: () { + Navigator.of(context).pop(); + sheetNavigator.pop(); + }, + ), + CupertinoButton( + child: const Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }); }, child: CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( diff --git a/sheet/example/lib/examples/sheet/fold_screen_sheet.dart b/sheet/example/lib/examples/sheet/fold_screen_sheet.dart index f238ba84..75d7731b 100644 --- a/sheet/example/lib/examples/sheet/fold_screen_sheet.dart +++ b/sheet/example/lib/examples/sheet/fold_screen_sheet.dart @@ -3,7 +3,7 @@ import 'package:sheet/sheet.dart'; class FoldableScreenFloatingSheet extends StatefulWidget { @override - State createState() => _FitSheetState(); + State createState() => _FitSheetState(); } class _FitSheetState extends State { diff --git a/sheet/example/lib/examples/sheet/sheet_without_momentum.dart b/sheet/example/lib/examples/sheet/sheet_without_momentum.dart index 31814400..d80a47c1 100644 --- a/sheet/example/lib/examples/sheet/sheet_without_momentum.dart +++ b/sheet/example/lib/examples/sheet/sheet_without_momentum.dart @@ -6,7 +6,7 @@ import 'package:sheet/sheet.dart'; class NoMomentumSheet extends StatefulWidget { @override - State createState() => _NoMomentumSheetState(); + State createState() => _NoMomentumSheetState(); } class _NoMomentumSheetState extends State { diff --git a/sheet/example/lib/examples/sheet/snap_sheet.dart b/sheet/example/lib/examples/sheet/snap_sheet.dart index 2ff8e77f..8f32391f 100644 --- a/sheet/example/lib/examples/sheet/snap_sheet.dart +++ b/sheet/example/lib/examples/sheet/snap_sheet.dart @@ -6,7 +6,7 @@ import 'package:sheet/sheet.dart'; class SnapSheet extends StatefulWidget { @override - State createState() => _SnapSheetState(); + State createState() => _SnapSheetState(); } class _SnapSheetState extends State { diff --git a/sheet/example/lib/examples/sheet/text_field.dart b/sheet/example/lib/examples/sheet/text_field.dart index 32b35c7b..fc9cdffb 100644 --- a/sheet/example/lib/examples/sheet/text_field.dart +++ b/sheet/example/lib/examples/sheet/text_field.dart @@ -4,7 +4,7 @@ import 'package:sheet/sheet.dart'; class TextFieldSheet extends StatefulWidget { @override - State createState() => _TextFieldSheetState(); + State createState() => _TextFieldSheetState(); } class _TextFieldSheetState extends State diff --git a/sheet/example/lib/route_example_page.dart b/sheet/example/lib/route_example_page.dart index bb4c3d2a..382e0802 100644 --- a/sheet/example/lib/route_example_page.dart +++ b/sheet/example/lib/route_example_page.dart @@ -234,8 +234,8 @@ class RouteExamplePage extends StatelessWidget { ), ), ListTile( - title: const Text( - 'Cupertino Navigator + Scroll + WillPopScope'), + title: + const Text('Cupertino Navigator + Scroll + PopScope'), onTap: () => Navigator.of(context).push( CupertinoSheetRoute( builder: (BuildContext context) => @@ -244,7 +244,7 @@ class RouteExamplePage extends StatelessWidget { ), ), ListTile( - title: const Text('Modal with WillPopScope'), + title: const Text('Modal with PopScope'), onTap: () => Navigator.of(context).push( CupertinoSheetRoute( builder: (BuildContext context) => @@ -253,7 +253,7 @@ class RouteExamplePage extends StatelessWidget { ), ), ListTile( - title: const Text('Modal Fit with WillPopScope'), + title: const Text('Modal Fit with PopScope'), onTap: () => Navigator.of(context).push( CupertinoSheetRoute( fit: SheetFit.loose, diff --git a/sheet/example/pubspec.lock b/sheet/example/pubspec.lock index ed1dbdb5..90b5b3b7 100644 --- a/sheet/example/pubspec.lock +++ b/sheet/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: "direct main" description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: @@ -88,6 +88,30 @@ packages: url: "https://pub.dev" source: hosted version: "12.1.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: "direct dev" description: @@ -108,26 +132,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" nested: dependency: transitive description: @@ -140,10 +164,10 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" provider: dependency: "direct main" description: @@ -158,7 +182,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0-pre" + version: "1.0.0" sky_engine: dependency: transitive description: flutter @@ -176,18 +200,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -208,10 +232,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" vector_math: dependency: transitive description: @@ -220,14 +244,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "13.0.0" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.7.0" diff --git a/sheet/example/pubspec.yaml b/sheet/example/pubspec.yaml index 24bf6c37..b7d2d570 100644 --- a/sheet/example/pubspec.yaml +++ b/sheet/example/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: ">=3.19.0 <4.0.0" + sdk: ">=3.3.0 <4.0.0" dependencies: flutter: diff --git a/sheet/lib/src/route/sheet_route.dart b/sheet/lib/src/route/sheet_route.dart index d06e27bf..83cd883a 100644 --- a/sheet/lib/src/route/sheet_route.dart +++ b/sheet/lib/src/route/sheet_route.dart @@ -182,7 +182,8 @@ class SheetRoute extends PageRoute with DelegatedTransitionsRoute { @protected bool shouldPreventPopForExtent(double extent) { return extent < willPopThreshold && - hasScopedWillPopCallback && + (hasScopedWillPopCallback || + popDisposition == RoutePopDisposition.doNotPop) && controller!.velocity <= 0; } @@ -466,20 +467,24 @@ class __SheetRouteContainerState extends State<_SheetRouteContainer> duration: const Duration(milliseconds: 400), curve: Curves.easeInOut, ); - - route.willPop().then( - (RoutePopDisposition disposition) { - if (disposition == RoutePopDisposition.pop) { - _sheetController.relativeAnimateTo( - 0, - duration: const Duration(milliseconds: 400), - curve: Curves.easeInOut, - ); - } else { - _sheetController.position.stopPreventingDrag(); - } - }, - ); + if (route.popDisposition == RoutePopDisposition.doNotPop) { + _sheetController.position.stopPreventingDrag(); + route.onPopInvoked(false); + } else { + route.willPop().then( + (RoutePopDisposition disposition) { + if (disposition == RoutePopDisposition.pop) { + _sheetController.relativeAnimateTo( + 0, + duration: const Duration(milliseconds: 400), + curve: Curves.easeInOut, + ); + } else { + _sheetController.position.stopPreventingDrag(); + } + }, + ); + } } @override