金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

getx-navigation

getx-navigation 是面向软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Context-less navigation, named routes, and middleware using GetX.

SKILL.md

下载 MD ↓
nameFlutter GetX Navigation
descriptionContext-less navigation, named routes, and middleware using GetX.
metadata{"labels": ["navigation", "getx", "routing", "middleware"], "triggers": {"files": ["**/app_pages.dart", "**/app_routes.dart"], "keywords": ["GetPage", "Get.to", "Get.off", "Get.offAll", "Get.toNamed", "GetMiddleware"]}}

GetX Navigation

Priority: P0 (CRITICAL)

Decoupled navigation system allowing UI transitions without BuildContext.

Implementation Guidelines

  • Prefer Named Routes: Use Get.toNamed('/path') for better maintainability. Define routes in a centralized AppPages class.
  • No Context Navigation: Leverage Get.to(), Get.back(), etc., directly from controllers.
  • Navigation Methods:
  • Get.to(): Navigate to next screen.
  • Get.off(): Navigate and replace current screen (e.g., Splash -> Home).
  • Get.offAll(): Clear stack and navigate (e.g., Logout -> Login).
  • Get.back(): Close current screen, dialog, or bottom sheet.
  • Bindings Everywhere: Always link routes with Bindings to manage controller lifecycles.
  • Middleware: Use GetMiddleware for route guards (Auth, Permissions) instead of logic inside views.

Code Example

// Route Definition
static final routes = [
  GetPage(
    name: _Paths.HOME,
    page: () => HomeView(),
    binding: HomeBinding(),
    middlewares: [AuthMiddleware()],
  ),
];

// Usage in Controller
void logout() {
  _authService.clear();
  Get.offAllNamed(Routes.LOGIN);
}

// Route Guard
class AuthMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    return isAuthenticated ? null : RouteSettings(name: Routes.LOGIN);
  }
}

Anti-Patterns

  • Mixing Context and GetX: Do not use Navigator.of(context) when GetX is the primary router.
  • Hardcoded Strings: Always use a Routes constant class for names.
  • Dialogs without GetX: Use Get.dialog() and Get.snackbar() for consistency.

Reference & Examples

For centralized route configuration and middleware guards: See references/app-pages.md and references/middleware-example.md.

Related Topics

getx-state-management | feature-based-clean-architecture

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本