搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。