Sailor은 Flutter 애플리케이션에서 네비게이션과 라우팅을 간소화하는 Flutter 패키지입니다. 명확하고 선언적인 방식으로 경로를 정의하고, 애니메이션을 포함한 페이지 전환을 관리하며, 디버깅 및 분석을 위해 네비게이션 이벤트를 로그 기록합니다. Sailor을 사용하면 개발자는 페이지 간에 쉽게 이동하고, 경로 간에 데이터를 전달하며, 딥링크를 처리할 수 있습니다. 기존의 Flutter 프로젝트에 원활하게 통합되며, 단순한 라우팅부터 복잡한 라우팅 요구 사항까지 지원합니다. 가벼운 설계와 직관적인 API는 구조화된 네비게이션 패턴이 필요한 앱에 이상적입니다.
사용 사례
간단한 앱 탐색
복잡한 경로 관리
페이지 전환 애니메이션
탐색 이벤트 로깅
딥링크 지원
상태 유지 라우팅 처리
주요 기능
선언적 라우트 정의
내장 애니메이션 지원
탐색 이벤트 로깅
경로 간의 데이터 전달이 쉬움
딥 링크 지원
최소한의 보일러플레이트
적합한 대상
초보자 플러터 개발자
중소에서 대규모의 플러터 앱
세부 탐색 추적을 필요로 하는 앱
복잡한 라우팅 로직을 가진 프로젝트
클린 코드 구조를 우선시하는 팀
고려 사항
제한된 플랫폼 고유의 사용자 정의
동적 경로에 대한 내장 지원 없음
Flutter의 위젯 트리에 대한 이해가 필요합니다
고급 기능을 사용하려면 추가 패키지가 필요할 수 있습니다
최소한의 탐색을 가진 매우 가벼운 앱에는 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
sailor
A Flutter package for easy navigation management.
Warning: Package is still under development, there might be breaking changes in future.
TIP: Sailor is a callable class, so you can omit navigate and directly call the method.
Routes.sailor("/secondPage");
Passing Parameters
Sailor allows you to pass parameters to the page that you are navigating to.
Before passing the parameter itself, you need to declare it while declaring your route. Let's declare a parameter named id that has a default value of 1234.
classSecondPageextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
final id = Sailor.param<int>(context, 'id');
...
}
}
Make sure to specify the type of paramter when declaring SailorParam<T>. This type is used to make sure when the route is being opened, it is passed the correct param type. Right now Sailor logs a warning if the type of declared and passed param is not same. In future version this might throw an error.
Passing Arguments
Sailor allows you to pass arguments to the page that you are navigating to.
The result from each route guard is Future<bool>. If the value returned by each route is true the route is accepted and opened, anything else will result in route being rejected and not being opened.
Transitions
Sailor has inbuilt support for page transitions. A transition is specified using SailorTransition.
Transition can be specified at 3 levels (ordered in priority from highest to lowest):
When Navigating (using Sailor.navigate).
While adding routes (SailorRoute).
Global transitions (SailorOptions).
When navigating
Specify which transitions to use when calling the navigate method.
More than one transition can be provided when navigating a single route. These transitions are composed on top of each other, so in some cases changing the order will change the animation.
NOTE: Custom transitions have the highest priority, if you provide a custom transition, they will be used over Sailor's inbuilt transitions.
The same priority rules apply to custom transitions as inbuilt sailor transitions, with the added rule that at any step if both transitions are provided (i.e. Sailor's inbuilt transitions and a CustomSailorTransition), the custom transition will be used over inbuilt one.
For example, in the below code, MyCustomTransition will be used instead of SailorTransition.slide_from_top.
Use SailorLoggingObserver to log the push/pop navigation inside the application.
Add the SailorLoggingObserver to the navigatorObservers list inside your MaterialApp.