搜索插件、代码仓与 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);
  },
);

所属分类

源码仓库

使用此插件的项目