搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。