首页/ AI 技能 / @skilllib/skill-2014279415222448129
Skill站外收录 @skilllib/skill-2014279415222448129

getx-navigation

提供无需 BuildContext 的路由跳转能力,支持命名路由、页面栈管理及中间件拦截,实现视图与导航逻辑解耦,适用于需要全局状态感知和权限控制的跨页面跳转场景。

0.0 (0) 551 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# 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 ```dart // 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](references/app-pages.md) and [references/middleware-example.md](references/middleware-example.md). ## Related Topics getx-state-management | feature-based-clean-architecture

评论 0

还没有评论,来抢沙发。