패키지, 저장소 및 앱 카테고리 검색

패키지 상세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입니다. 개발자가 완전한 네비게이션 흐름에 접근할 수 있도록 하여 뒤로 가기 버튼 동작 커스터마이징, 분석 또는 네비게이션 패턴 디버깅과 같은 기능을 가능하게 합니다. 이 관찰자는 모바일, 웹, 데스크톱을 포함한 모든 지원되는 플랫폼에서 실시간으로 라우트 전환을 캡처합니다. 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.