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

パッケージ詳細v1.1.1

navigation_history_observer

プッシュされたルートの履歴およびポップされた履歴を格納する Flutter NavigatorObserver。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3.1万
いいね数
70
Pub ポイント
160

パッケージをインストール

flutter pub add navigation_history_observer

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

navigation_history_observer は、ナビゲーション中にプッシュおよびポップされたルートの履歴を追跡・保存する Flutter の NavigatorObserver です。開発者が完全なナビゲーションフローにアクセスできるようにし、戻るボタンの挙動カスタマイズ、分析、またはナビゲーションパターンのデバッグなどの機能を可能にします。このオブザーバーは、モバイル、Web、デスクトップを含むすべての対応プラットフォームでリアルタイムでルート遷移をキャプチャします。Flutter のルーティングシステムとシームレスに統合され、pub add コマンドによる最小限のセットアップで利用可能です。

用途

  • ナビゲーションフローのデバッグ
  • カスタム戻るナビゲーションロジックの実装
  • 分析用のユーザー旅程のトラッキング
  • アプリの再起動後にナビゲーション状態を再作成する
  • リアルタイムでのルート遷移のモニタリング

主な機能

  • プッシュされたルートとポップされたルートの両方をトラッキングします
  • 完全なナビゲーション履歴を提供します
  • クロスプラットフォーム対応(Android、iOS、Web、macOS、Windows、Linux)
  • ナビゲーターとのシンプルな統合
  • リアルタイムルート変更モニタリング

適している対象

  • 複雑なナビゲーションワークフローを構築する開発者
  • 詳細なナビゲーション分析を必要とするアプリ
  • カスタムナビゲーション動作を実装するチーム
  • ルート関連の問題のデバッグ
  • 状態の復元が必要なアプリケーション

注意事項

  • 深いナビゲーションスタックによりメモリ使用量が増加する可能性があります
  • 履歴データの手動管理が必要です
  • 軽量なナビゲーション要件には適していません
  • MaterialApp または CupertinoApp とのみ使用可能
  • ナビゲーターの観察者に適切に登録されるべきです

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Flutter Navigation History Observer

A flutter navigation observer that adds access to lists that track the navigation stack both forwards and backwards.

Usage

This is a singleton, meaning you can access its single instance from anywhere by calling the default constructor.

To initialize the first instance you must add it to your app's navigator observers list like so:

void main() {
  runApp(MaterialApp(
    home: Container(),
    navigatorObservers: [NavigationHistoryObserver()],
  ));
}
History:

To access the history, use NavigationHistoryObserver().history from anywhere in your code.

Use NavigationHistoryObserver().top to peek on the navigation stack's top element - which would be the current route.

Popped routes (forwards history):

To access the popped routes, use NavigationHistoryObserver().poppedRoutes from anywhere in your code.

UseNavigationHistoryObserver().next to get the most recent popped route.

This feature is intended to track the pages visited by the user, rather than navigating forwards. Please keep in mind that popped routes have already been disposed, meaning that you can't simply navigate to them as is via Navigator.push(context, route).

If you'd still like to navigate forwards, you may try Navigator.pushNamed(context, name), whereas the name should be extracted from route.settings.name provided that you're using named routes in your app.
However, there's no guarantee that it'll work.

Nevertheless, I discourage having forwards-navigation in your app.

History Change Stream:

The NavigationHistoryObserver class holds a StreamController that broadcasts each time the navigation stack changes.

Use NavigationHistoryObserver().historyChangeStream.listen((change) => action) to listen for changes.

The change object is of type HistoryChange. It holds the following properties:

  1. action - a NavigationStackAction enum reporting the action that caused this change. Values: push, pop, remove, replace.
  2. newRoute - the new route that was added/removed from the stack.
  3. oldRoute - the old route that was in place before this action happened.

This provides you with an easy-to-use interface that allows updating states across your app whenever the navigation stack changes. See the example for basic usage.

Developer's Note:

The history and poppedRoutes getters return clones of the actual private collections as BuiltLists, meaning they're immutable. To change these collections, use the default Navigator as you normally would, and they'll update as you navigate throughout your app.

Special Thanks

  • Shoutout to the Flutter Israel Developers community for being supportive and encouraging me to create this package.
  • Special thanks to Sahar Vanunu for giving me the original idea for this package.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

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