パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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スタイルのナビゲーションにおけるUXの向上
  • 誤ったナビゲーションを防ぐ
  • 戻りスワイプ時に確認ダイアログを実装する
  • スワイプバックフィードバックの向上

主な機能

  • Cupertino のトランジションでの onWillPop をサポート
  • 拒否されたスワイプジェスチャーの視覚フィードバック
  • CupertinoPageScaffold およびルートと連携可能
  • 最小限のボイラープレート統合
  • クロスプラットフォーム互換性
  • 戻るジェスチャー制御のためのクリーンな API

適している対象

  • Cupertino ナビゲーションを使用した iOS スタイルのアプリ
  • カスタムの戻るナビゲーションロジックが必要なアプリ
  • スワイプバックのUXを向上させる開発者
  • ポップする前に確認が必要なプロジェクト
  • 一貫したモバイルナビゲーションを構築するチーム
  • 複数のプラットフォーム向けのFlutterアプリ

注意事項

  • CupertinoPageScaffold の使用が必要です
  • iOSスタイルのナビゲーションパターンに限定
  • 他のルートインターセプタと競合する可能性があります
  • マテリアルデザインアプリには不要
  • 明示的なバックハンドリングと併用すると最適です
  • 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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。