搜索插件、代码仓与 APP 分类

插件详情v5.6.0

go_router_modular

使用 GoRouter 的 Flutter 模块化路由和依赖注入。支持事件驱动架构,实现模块间无缝通信,并提供微前端支持。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
303
喜欢数
35
Pub 分数
140

安装插件

flutter pub add go_router_modular

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

GoRouter Modular 是一个 Flutter 包,它通过模块化路由和依赖注入增强了 GoRouter,从而实现可扩展的应用架构。它支持模块之间的事件驱动通信,并促进微前端模式。专为大规模应用设计,它促进了代码分离、可重用性以及独立的模块开发。该包与 GoRouter 无缝集成,同时扩展了其在复杂导航和跨模块组件状态管理方面的能力。

适合场景

  • 大规模 Flutter 应用
  • 微前端架构
  • 模块化应用开发
  • 独立模块部署
  • 事件驱动的模块间通信
  • 可扩展的导航系统

主要特点

  • 使用 GoRouter 的模块化路由
  • 内置依赖注入
  • 事件驱动的模块通信
  • 对微前端的支持
  • 轻松集成模块
  • 跨平台兼容性

适合对象

  • 开发复杂 Flutter 应用的开发者
  • 使用模块化架构的团队
  • 需要可重用 UI 组件的项目
  • 具有多个功能模块的应用程序
  • 注重可扩展性的工程团队

使用建议

  • 需要了解 GoRouter
  • 初学者的学习曲线更陡峭
  • 模块注册的额外设置
  • 可能增加构建复杂性
  • 最适合大型项目,而非小型应用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Go Router Modular

🧩 GoRouter Modular 💉

Modular architecture, dependency injection & route management on top of GoRouter.

Pub Version Pub Points GitHub Stars License

GoRouter Modular brings a modular architecture on top of GoRouter, with per-module dependency injection and automatic dispose. Split a large app into independent, lazy-loaded feature modules — perfect for micro frontends and scalable, team-friendly codebases. 🚀

Read the Docs

💡 Inspired by flutter_modular by Flutterando — we're grateful for their contribution to the Flutter ecosystem.


✨ Features

🧩 Modular Architecture Independent, reusable feature modules
💉 Dependency Injection Built-in DI with automatic dispose
🛣️ GoRouter Integration Type-safe, declarative navigation
🎭 Event System Decoupled, event-driven communication between modules
🚀 Lazy Loading Modules load on demand with efficient memory management
🛡️ Type Safety Fully type-safe with compile-time checks

📦 Installation

flutter pub add go_router_modular

🚀 Quick Start

1. Configure & run — bootstrap in main.dart:

import 'package:flutter/foundation.dart'; // kDebugMode
import 'package:flutter/material.dart';
import 'package:go_router_modular/go_router_modular.dart';

import 'src/app_module.dart';
import 'src/app_widget.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Modular.configure(
    appModule: AppModule(),
    initialRoute: '/',
    // Logs only in debug builds — release stays quiet.
    debugLogDiagnostics: kDebugMode,
  );

  runApp(const AppWidget());
}

class AppWidget extends StatelessWidget {
  const AppWidget({super.key});

  @override
  Widget build(BuildContext context) => ModularApp.router(title: 'My App');
}

2. Compose modules — the root AppModule registers app-wide binds and mounts each feature:

class AppModule extends Module {
  @override
  void binds(Injector i) {
    i
      ..addSingleton<DioClient>((i) => DioClient())
      ..addSingleton<AuthStore>((i) => AuthStore());
  }

  @override
  List<ModularRoute> get routes => [
        ModuleRoute('/', module: HomeModule()),
        ModuleRoute('/profile', module: ProfileModule()),
      ];
}

3. Define a feature module — its own binds and routes, disposed automatically when you leave it:

class HomeModule extends Module {
  @override
  void binds(Injector i) => i.addSingleton<HomeController>((i) => HomeController());

  @override
  List<ModularRoute> get routes => [
        ChildRoute(
          '/',
          name: 'home',
          child: (context, state) => HomePage(controller: Modular.get<HomeController>()),
        ),
      ];
}

4. Navigate — named-only, type-safe:

context.goNamed('profile');            // replace the stack
context.pushNamed('home');             // push on top
final controller = Modular.get<HomeController>(); // resolve a dependency

🤖 Agent Skill

This repo ships an Agent Skill that teaches AI coding agents (Claude Code, Cursor, Codex, OpenCode, and others) the recommended conventions for this package — per-feature route files, named-only navigation, typed binds via the .. cascade, synchronous modules, and kDebugMode-gated logs. The agent then applies them automatically when you scaffold routes, modules, or navigation.

Install it into your project with one command (via the skills CLI):

npx skills add eduardohr-muniz/go_router_modular -s go-router-modular

The CLI detects your installed agents and drops the skill into the right place (e.g. .claude/skills/). Add -g to install it globally for every project.

Optional — events add-on

If your app uses the event system (EventModule, ModularEvent, ModularEventMixin) for decoupled cross-module communication, install the separate events skill too:

npx skills add eduardohr-muniz/go_router_modular -s go-router-modular-events

🤝 Contributing

Contributions are very welcome! Open an issue to discuss major changes, then submit a PR with a clear description of the edits.

📄 License

Distributed under the MIT license. See LICENSE for details.


Transform your Flutter app into a scalable, modular masterpiece. ✨

Contributors

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

暂无相关数据。