cupertino_will_pop_scope 1.0.0 copy "cupertino_will_pop_scope: ^1.0.0" to clipboard
cupertino_will_pop_scope: ^1.0.0 copied to clipboard

outdated

This package extends the default iOS page transition to support the invocation of `onWillPop` in a [WillPopScope] widget.

CupertinoWillPopScope #

pub package

This package is a modified version of Flutter's CupertinoPageRoute. It adds the following enhancements:

  1. 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.
  2. 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.
53
likes
0
pub points
94%
popularity

Publisher

verified publisherbenpesso.com

This package extends the default iOS page transition to support the invocation of `onWillPop` in a [WillPopScope] widget.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on cupertino_will_pop_scope