搜索插件、代码仓与 APP 分类

插件详情v1.2.1

cupertino_will_pop_scope

在Cupertino页面转换中启用'onWillPop'回调,并改进被拒绝的“向左滑动返回”手势的视觉反馈。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8910
喜欢数
58
Pub 分数
140

安装插件

flutter pub add cupertino_will_pop_scope

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

cupertino_will_pop_scope 包通过在 iOS 风格的导航中启用页面过渡期间的 onWillPop 回调,扩展了 Flutter 的 Cupertino 小部件。当滑动返回手势被拒绝时,它提供视觉反馈,从而提升用户体验,确保导航更加流畅和直观。该包特别适用于需要在返回前进行自定义确认逻辑的应用程序,例如表单验证或未保存的更改。它可与现有的 CupertinoPageScaffold 和 CupertinoPageRoute 实现无缝集成。

适合场景

  • 导航前处理未保存的更改
  • 自定义返回手势验证
  • 改进iOS风格导航的用户体验
  • 防止意外导航
  • 在向后滑动时实现确认对话框
  • 增强滑动返回反馈

主要特点

  • 支持 Cupertino 转场中的 onWillPop
  • 对被拒绝的滑动手势的视觉反馈
  • 与 CupertinoPageScaffold 和路由配合使用
  • 最小化样板代码集成
  • 跨平台兼容性
  • 用于返回手势控制的简洁 API

适合对象

  • 使用 Cupertino 导航的 iOS 风格应用
  • 需要自定义返回导航逻辑的应用
  • 开发者增强滑动返回用户体验
  • 在弹出前需要确认的项目
  • 构建一致的移动导航的团队
  • Flutter 应用程序针对多个平台

使用建议

  • 需要使用 CupertinoPageScaffold
  • 仅限iOS风格的导航模式
  • 可能与其他路由拦截器冲突
  • Material Design 应用不需要
  • 最好配合明确的后处理使用
  • 不影响 Android 返回行为

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。