Search packages, repositories and app categories

Package detailsv1.2.1

cupertino_will_pop_scope

Enables 'onWillPop' callbacks on Cupertino page transitions and improves visual feedback of rejected "Swipe to go back" gestures.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
8.9K
Likes
58
Pub points
140

Install package

flutter pub add cupertino_will_pop_scope

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The cupertino_will_pop_scope package extends Flutter's Cupertino widgets by enabling onWillPop callbacks during page transitions on iOS-style navigation. It enhances user experience by providing visual feedback when a swipe-to-go-back gesture is rejected, ensuring smoother and more intuitive navigation. This package is particularly useful for apps that require custom confirmation logic before navigating back, such as form validation or unsaved changes. It integrates seamlessly with existing CupertinoPageScaffold and CupertinoPageRoute implementations.

Use cases

  • Handling unsaved changes before navigation
  • Custom back gesture validation
  • Improving UX in iOS-style navigation
  • Preventing accidental navigation
  • Implementing confirmation dialogs on back swipe
  • Enhancing swipe-back feedback

Key features

  • Supports onWillPop in Cupertino transitions
  • Visual feedback for rejected swipe gestures
  • Works with CupertinoPageScaffold and routes
  • Minimal boilerplate integration
  • Cross-platform compatibility
  • Clean API for back gesture control

Suitable for

  • iOS-style apps using Cupertino navigation
  • Apps needing custom back navigation logic
  • Developers enhancing swipe-back UX
  • Projects requiring confirmation before pop
  • Teams building consistent mobile navigation
  • Flutter apps targeting multiple platforms

Considerations

  • Requires CupertinoPageScaffold usage
  • Limited to iOS-style navigation patterns
  • May conflict with other route interceptors
  • Not needed for Material design apps
  • Best used with explicit back handling
  • Does not affect Android back behavior

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

CupertinoWillPopScope

pub package

Note: This package can be used on any platform, and is not specific to iOS. ConditionalWillPopScope and CupertinoWillPopScopePageTransionsBuilder can each be used seprately.


CupertinoWillPopScopePageTransionsBuilder

The key to this package is a modified version of Flutter's CupertinoPageRoute, which has been enhanced with the following:

  • Visual feedback when users attempt to "swipe to go back" - the screen is allowed to be dragged a bit before it is snapped back to place.
  • If an enclosing route has willPop callbacks, they are triggered once the screen is snapped back to place.
ConditionalWillPopScope

When using this widget, be sure to update shouldAddCallbacks based on the state of your screen, and only set it to true when the screen should not be allowed to pop. Additionally, the onWillPop property should not be changed once set.


A working app using this package 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

Set the transition builder of the desired platform to CupertinoWillPopScopePageTransionsBuilder in your theme configuration.

// main.dart
theme = ThemeData(
  ...
  pageTransitionsTheme: PageTransitionsTheme(
    builders: {
      TargetPlatform.android: ZoomPageTransitionsBuilder(),
      TargetPlatform.iOS: CupertinoWillPopScopePageTransionsBuilder(),
    },
  ),
);
Make sure the theme is applied to the app.
// main.dart
MaterialApp(
  ...
  theme: theme,
  home: HomeScreen(),
);
Wrap your screen

Using the included ConditionalWillPopScope widget, or Flutter's WillPopScope widget, wrap your screen and define an onWillPop callback for it.

Note that onWillPop should always return a bool. See the Flutter Docs for more.
Using ConditionalWillPopScope:
// my_screen.dart
@override
Widget build(BuildContext context) {
  return ConditionalWillPopScope(
    child: _MyScreenContent(),
    onWillPop: _onWillPop,
    shouldAddCallbacks: _hasChanges,
  );
}
Using WillPopScope:
// my_screen.dart
@override
Widget build(BuildContext context) {
  return WillPopScope(
    child: _MyScreenContent(),
    onWillPop: _hasChanges ? _onWillPop : null,
  );
}

:warning: When using Flutter's WillPopScope widget, the onWillPop must be set conditionally. Otherwise, the "swipe to go back" gesture will be cancelled. In the example above, this is achieved by using _hasChanges as the condition.

Categories

Source repository

Projects using this package

No data available yet.