go_router_plus는 Go Router를 기반으로 한 강화된 라우팅 기능을 제공하며, 모듈식 화면 정의, 역할 기반 접근 제어, 내장 알림을 통한 자동 상태 갱신을 지원합니다. 복잡한 라우팅 로직을 재사용 가능한 컴포넌트로 추상화하여 Flutter 앱에서 탐색을 단순화합니다. 이 패키지는 모든 주요 플랫폼을 지원하므로 동적 접근 요구사항과 실시간 UI 업데이트가 필요한 확장성 있고 유지보수가 쉬운 애플리케이션에 이상적입니다. 최소한의 반복 코드로 구조적인 라우팅 접근을 원하는 개발자를 위한 설계입니다.
사용 사례
동적 경로를 가진 단일 페이지 애플리케이션
다양한 역할 사용자 대시보드
새로고침 알림자를 통한 실시간 UI 업데이트
모듈러 앱 아키텍처
크로스 플랫폼 라우팅 일관성
보호된 경로 처리
주요 기능
모듈러 스크린 정의
역할 기반 접근 제어
내장형 새로 고침 알림
플랫폼에 관계없는 라우팅
확장 가능한 경로 구성
Go Router와의 간편한 통합
적합한 대상
확장 가능한 플러터 앱을 개발하는 개발자
중앙 집중형 라우팅 로직이 필요한 팀
복잡한 액세스 제어를 가진 앱
자동 UI 새로 고침이 필요한 프로젝트
다중 플랫폼을 대상으로 한 Flutter 앱
고려 사항
Go Router에 익숙해야 합니다
패키지 크기가 약간 증가할 수 있습니다
외부 상태 관리 패턴에 의존합니다
중대형 프로젝트에 가장 적합
기본 설정 외에는 문서가 제한적입니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Go Router Plus
Go Router is an awesome easy-to-use and production ready package for creating routes, handling
navigation, deep and dynamic links but in large apps have a lot of screens, states and auth logics,
it's hard to manage routes, redirect and refresh router logics.
This package try to solve problems above by adding screen pattern, common redirect logics and
chain redirect/refresh listenable.
Screen represent for route of your application, the purpose of
it is separate GoRoute factory logics out of GoRouter factory for
easy-to-read and maintaining.
All of your screens must be extends an abstraction class Screen providing by this package.
The following methods, getters need to implements:
Method build(BuildContext context, GoRouterState state) must be redeclare return
type to Widget or Page<void>, in common case you should use Widget but if you want to control
the transition of screen you should use Page<void>.
Getter routeName declare route name of the screen must be unique.
Getter routePath declare route path of the screen.
Mark screen as an initial screen
To setup initial path (the first screen user will see) in traditional way, we will set initialPath
argument of GoRouter factory but when using this package you need to create the screen implements InitialScreen interface instead.
As you know, GoRouter factory offer we an errorBuilder
argument to handling error (e.g route not found) but when using this package you need to create the screen implements ErrorScreen interface instead.
ShellRoute was added since go router v5
provides a way to wrap all sub-routes with a UI shell. Under the hood, GoRouter places a Navigator
in the widget tree, which is used to display matching sub-routes, you can use this feature by
extends ShellScreen class:
It's a simple interface need you implements loggedIn getter,
this getter return true when user has been logged in otherwise
user's guest (not logged in).
And you need to marks guest and user screens of you app by using UserScreen and GuestScreen interfaces:
In example above, we have two screen, one for guest (login screen) and one for
user (home screen). When user is NOT logged in he/she will be redirect
to login screen otherwise he/she will redirect to home screen, to handling
this scenario, we need to add AuthRedirector with the setting bellow:
Now everytime user access to screens implements UserScreen interface but
he/she's NOT logged in will be redirect to login screen and if they access to
screens implements GuestScreen interface but logged in will be redirect to home screen.
Screen redirection
It's a builtin feature to support screens have a custom redirect logic (e.g: access control by app states, user roles).
Screens want to build custom redirect logic should be implements RedirectAware:
Like origin redirection,
redirect method above return null in case current user's VIP type so user can stay
in this screen, on the other hand normal user will be redirect to home screen.
And to activate this feature pass ScreenRedirector instance to redirectors argument of factory function:
In some cases, you may want to control redirection logics for common screens like AuthRedirector or ScreenRedirector above
(e.g: add an interface to marks some screens only admin user can access).
In the example above, we have add the AdminScreen interface use to marks screens for admin user only,
if user's not permit will be redirect to home screen.
AdminRedirector implements RestrictRedirector interface only execute redirect method when
shouldRedirect method return true otherwise it'll skip. In this case, shouldRedirect method
only return true when current screen implements AdminScreen.
The final step is add custom redirector to redirectors argument of factory function
Refresh listenable is a builtin feature of GoRouter
to re-invoke redirection logics but it only accept one listenable and we need to implements all of
re-invoke logics in one place.
With this package you can add more than one listenable to re-invoke redirection logics so you can separate logics to easy control,
readable and independent to each others.
Pass one or more listenable instance to refreshNotifiers argument of factory function:
In the example above, AuthService class's a refresh notifier and implements LoggedInState interface
to providing state of current user's logged-in or guest. When user logout AuthRedirector will invoke
and redirect he/she to login screen. In the other hand, promotion service will invoke redirection logic
when activate promotion (e.g: move user to promotion screen).