cupertino_will_pop_scope 1.0.0
cupertino_will_pop_scope: ^1.0.0 copied to clipboard
This package extends the default iOS page transition to support the invocation of `onWillPop` in a [WillPopScope] widget.
CupertinoWillPopScope #
This package is a modified version of Flutter's CupertinoPageRoute. It adds the following enhancements:
- Visual indication is added to routes when users attempt to swipe back - the screen is allowed to be dragged a ⅓ of the way, and then it is snapped back.
- The route's
willPop
callbacks are triggered when users attemp to swipe back.
A working example can be found in the example folder.
Usage #
To use this package, add cupertino_will_pop_scope
as a dependency in your pubspec.yaml file.
Example #
Import the library #
// main.dart
import 'package:decorated_icon/cupertino_will_pop_scope.dart';
Configure page transitions #
In your theme
, set the Target.iOS
transition builder to CupertinoWillPopScopePageTransionsBuilder()
.
// main.dart
theme = ThemeData(
...
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilderCustomBackGestureWidth(),
},
),
);
Then apply the theme to the app.
// main.dart
MaterialApp(
theme: theme,
home: HomeScreen(),
);
Use a WillPopScope
widget #
Wrap your screen with a WillPopScope widget and set its onWillPop
callback.
// my_screen.dart
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _hasChanges ? _onWillPop : null,
child: _MyScreenContent(),
);
}
⚠️ IMPORTANT |
---|
• onWillPop must be set conditionally. Otherwise, the "swipe to go back" gesture may not work properly.In the example above, _hasChanges is a bool that is set to true via setState whenever the back navigation should be disabled.• onWillPop should return a bool . See the Flutter Docs for more. |