RouteFly는 Next.js에서 영감을 받은, Flutter용 폴더 기반 라우팅 관리 패키지로, Flutter 애플리케이션 내의 탐색을 단순화하기 위해 설계되었습니다. 정의된 폴더 구조에서 자동으로 라우트를 생성하여 반복 코드를 줄이고 코드 조직을 개선합니다. Flutterando 커뮤니티가 개발했으며, Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다. RouteFly는 수동 라우트 등록 없이 직관적이고 확장 가능한 라우팅을 가능하게 하여 개발자 생산성을 향상시킵니다.
사용 사례
폴더 구조에서 자동 경로 생성
대규모 Flutter 앱에서 탐색 간소화
경로 로직의 명확한 분리 활성화
다중 플랫폼 Flutter 프로젝트 지원
팀 환경에서 경로 관리 간소화
주요 기능
폴더 기반 경로 정의
자동 경로 생성
최소한의 보일러플레이트
크로스 플랫폼 지원
Flutterando 생태계와의 통합
적합한 대상
폴더 기반 프로젝트 구조를 사용하는 개발자
확장 가능한 라우팅 솔루션을 찾는 팀
수동 경로 설정을 줄이려는 프로젝트
Next.js 관행에 익숙한 Flutter 개발자
다중 플랫폼을 대상으로 하는 앱
고려 사항
특정 폴더 이름 지정 규칙을 준수해야 합니다
복잡한 경로 매개변수에 대한 구성이 필요할 수 있습니다
구조화된 디렉터리 레이아웃을 가진 프로젝트에 가장 적합
수동 경로 설정과 비교해 사용자 지정이 제한됨
업데이트는 Flutterando의 유지보수자에 따라 달라집니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Routefly
Routefly is a folder-based route manager inspired by NextJS and created by the Flutterando community. It allows you to automatically create routes in your Flutter app by simply organizing your code files within specific directories. When a file is added to the "pages" directory, it's automatically available as a route. Just add the appropriate folder structure inside the "lib/app" folder.
Example:
Sponsors
Installation and Initialization
To get started with Routefly, follow these steps:
Add the Routefly package to your Flutter project:
flutter pub add routefly
You will need to add the @Main() annotation to the main Widget (usually the one containing MaterialApp or CupertinoApp). After adding the necessary imports and parts, the code will be ready to generate the routes.
It is also necessary to use Navigator 2.0, accessed through the MaterialApp.router or CupertinoApp.router constructor, adding the custom routerConfig from Routefly:
Run this command every time you create a new folder with a page to generate the routes again. You can also use the --watch flag to automatically generate routes when adding a new page to a folder.
Route Groups
In the app directory, nested folders are normally mapped to URL paths. However, you can mark a folder as a Route Group to prevent the folder from being included in the route's URL path.
This allows you to organize your route segments and project files into logical groups without affecting the URL path structure.
A route group can be created by wrapping a folder's name in parenthesis: (folderName)
Routefly.navigate('path'): Replaces the entire route stack with the requested path. Routefly.pushNavigate('path'): Adds a new route on top of the existing stack. Routefly.push('path'): Adds a route to the route stack. Routefly.pop(): Removes the top route from the route stack. Routefly.replace('path'): Replaces the last route in the stack with the requested path.
You can use RELATIVE PATH also;
It is also possible to access routes using Record routePaths which replaces the strings
which represent the path by an object notation.
Dynamic Routes allow you to create routes from dynamic data. You can use dynamic segments enclosed in brackets, such as [id] or [slugs]. For example:
Create a page using a dynamic segment: lib/app/users/[id]/user_page.dart. This generates the route path /users/[id].
Use navigation commands to replace the dynamic segment, like Routefly.push('/users/2').
Access the dynamic parameter (id) on the page using Routefly.query['id'].
You can also access segment parameters using Routefly.query.params, e.g., Routefly.query.params['search'] for /product?search=Text.
Custom Transition
To create custom route transitions, define a routeBuilder function in your page file. This allows you to use custom transitions based on PageRouteBuilder. For example:
To create a layout, create the folder it will belong to and add a *_layout.dart file. The child folders must be inside the layout's parent folder.
In the Layout Widget, add RouterOutlet() wherever you prefer nested routes to appear.
ex:
RouterOutlet(),
Tip
If the error occurs:
EXCEPTION CAUGHT BY RENDERING LIBRARY
The following assertion was thrown during performResize().
This error usually occurs in lists, columns and rows when an element does not have a defined size. To fix it, you can use, for example, Expanded, Center or SizedBox. In this example, I chose to use Expanded.
When creating a route with name 404, it will be triggered when a page is not found.
Routefly gives the possibility to modify the default route for unfound pages.