搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.5

fluro

Fluro 是一個空安全的 Flutter 路由庫,提供靈活的路由選項,例如萬用字元、命名參數和明確的路由定義。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2.3萬
喜歡數
891
Pub 分數
150

安裝套件

flutter pub add fluro

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Fluro 是一個空安全的 Flutter 路由庫,旨在透過靈活的路由設定簡化導航。它支援萬用字元、命名參數和乾淨的宣告式路由定義,讓跨多個平台管理複雜的導航流程變得輕鬆。適合需要動態路由模式的應用程式,Fluro 提升了程式碼的可讀性和可維護性。其輕量級特性和與 Android、iOS、Web、macOS、Windows 及 Linux 的相容性,使其成為現代 Flutter 應用的多功能選擇。

適用情境

  • 複雜的導航與動態路由
  • 參數化 URL 路由
  • 跨平台應用導航
  • 模組化應用架構
  • 深度連結支援
  • 路由邏輯的清晰分離

主要特色

  • 萬用字元路由比對
  • 命名參數支援
  • 宣告式路由定義
  • 空安全 API
  • 輕量且高效
  • Platform-agnostic

適合對象

  • 需要高級路由的開發人員
  • 具有深度連結需求的應用程式
  • 大規模Flutter專案
  • 優先考慮程式碼結構清晰的團隊
  • 面向多個平台的專案

使用建議

  • 需要手動註冊路由
  • 有限的內建導航狀態管理
  • 比基礎導航器的學習曲線更陡峭
  • 不再積極維護(最後更新時間 2021)
  • 社群支援主要透過 GitHub 問題

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

English | Português



The brightest, hippest, coolest router for Flutter.

Version Build Status

Features

  • Simple route navigation
  • Function handlers (map to a function instead of a route)
  • Wildcard parameter matching
  • Querystring parameter parsing
  • Common transitions built-in
  • Simple custom transition creation
  • Follows stable Flutter channel
  • Null-safety

Example Project

There is a pretty sweet example project in the example folder. Check it out. Otherwise, keep reading to get up and running.

Getting started

First, you should define a new FluroRouter object by initializing it as such:

final router = FluroRouter();

It may be convenient for you to store the router globally/statically so that you can access the router in other areas in your application.

After instantiating the router, you will need to define your routes and your route handlers:

var usersHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return UsersScreen(params["id"][0]);
});

void defineRoutes(FluroRouter router) {
  router.define("/users/:id", handler: usersHandler);

  // it is also possible to define the route transition to use
  // router.define("users/:id", handler: usersHandler, transitionType: TransitionType.inFromLeft);
}

In the above example, the router will intercept a route such as /users/1234 and route the application to the UsersScreen passing the value 1234 as a parameter to that screen.

Navigating

You can use FluroRouter with the MaterialApp.onGenerateRoute parameter via FluroRouter.generator. To do so, pass the function reference to the onGenerate parameter like: onGenerateRoute: router.generator.

You can then use Navigator.push and the flutter routing mechanism will match the routes for you.

You can also manually push to a route yourself. To do so:

router.navigateTo(context, "/users/1234", transition: TransitionType.fadeIn);

Class arguments

Don't want to use strings for params? No worries.

After pushing a route with a custom RouteSettings you can use the BuildContext.settings extension to extract the settings. Typically this would be done in Handler.handlerFunc so you can pass RouteSettings.arguments to your screen widgets.

/// Push a route with custom RouteSettings if you don't want to use path params
FluroRouter.appRouter.navigateTo(
  context,
  'home',
  routeSettings: RouteSettings(
    arguments: MyArgumentsDataClass('foo!'),
  ),
);

/// Extract the arguments using [BuildContext.settings.arguments] or [BuildContext.arguments] for short
var homeHandler = Handler(
  handlerFunc: (context, params) {
    final args = context.settings.arguments as MyArgumentsDataClass;

    return HomeComponent(args);
  },
);

所屬分類

原始碼儲存庫

使用此套件的專案