GetX Plus
简洁、轻量的 GetX 分支:在不依赖 BuildContext 的情况下进行路由导航、状态管理与依赖注入。本项目用于继续维护原项目在上游不再及时更新的场景,同时保持 API 兼容(基于 4.7.3)。
English summary: This is a lightweight maintained fork of GetX (version 4.7.3 baseline). Same core APIs for state, route, and dependency management. See upstream docs for full details.
与原项目的关系
- 上游仓库: https://github.com/jonataslaw/getx (完整 README 与历史说明)
- 本仓库为
getx_plus,目标:小幅维护、问题修复、偶发增强,不做破坏性重构。 - 若需全面深入教程/高级特性,请直接跳转原 README: https://github.com/jonataslaw/getx/blob/master/README.md
为什么精简
原 README 内容非常庞大;这里仅保留快速上手与入口导航,降低阅读成本。深入内容 → 参见下方“详细文档”。
安装
在 pubspec.yaml 中添加:
dependencies:
getx_plus: ^4.7.3
导入:
import 'package:getx_plus/get.dart';
快速示例(计数器)
import 'package:flutter/material.dart';
import 'package:getx_plus/get.dart';
void main() => runApp(GetMaterialApp(home: Home()));
class CounterController extends GetxController {
final count = 0.obs;
void inc() => count++;
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
final c = Get.put(CounterController());
return Scaffold(
appBar: AppBar(title: Obx(() => Text('Clicks: ${c.count}'))),
body: Center(
child: ElevatedButton(
onPressed: () => Get.to(const Other()),
child: const Text('Go to Other'),
),
),
floatingActionButton: FloatingActionButton(onPressed: c.inc, child: const Icon(Icons.add)),
);
}
}
class Other extends StatelessWidget {
const Other({super.key});
@override
Widget build(BuildContext context) {
final c = Get.find<CounterController>();
return Scaffold(body: Center(child: Obx(() => Text('Total: ${c.count}'))));
}
}
核心点:
.obs创建可观察变量Obx(() => ...)响应式刷新Get.put()注入依赖;Get.find()获取GetMaterialApp提供路由/国际化/snackbar/dialog 能力
常用速查
| 场景 | 调用 |
|---|---|
| 跳转页面 | Get.to(Widget()) |
| 返回上一层 | Get.back() |
| 替换当前 | Get.off(Widget()) |
| 清空并跳转 | Get.offAll(Widget()) |
| 注入依赖 | Get.put(Controller()) |
| 查找依赖 | Get.find<Controller>() |
| 状态变量 | var x = 0.obs; |
| 监听刷新 | Obx(() => Text('$x')) |
详细文档入口
本地精简索引(与原项目英文文档路径保持一致):
- 状态管理:
documentation/en_US/state_management.md - 路由管理:
documentation/en_US/route_management.md - 依赖管理:
documentation/en_US/dependency_management.md
多语言(文件结构已存在,可直接打开):documentation/<lang_code>/ 下同名文件。
示例: documentation/zh_CN/state_management.md
若这些文件缺少更新,请以上游 README 为准。
目标与原则
- 保持 API 行为兼容,减少升级风险
- 优先修复 bug & 适配新 Flutter 版本
- 不主动引入复杂生成器/宏
参与贡献
欢迎 issue / PR:
- 提交前请尽量复用原风格
- 保持向后兼容;若需破坏性变更请先开 issue 讨论
- 添加最小化测试或示例片段
常见问题 (FAQ 简版)
- 需要 context 吗?大多数 GetX API 不需要
- 必须使用
GetMaterialApp吗?仅在使用路由/国际化/snackbar/dialog 等功能时需要 - 与 Provider / Riverpod 能共存吗?可以,只用其依赖注入或部分能力即可
License
沿用上游项目 LICENSE。
引用与致谢
感谢原作者与社区贡献者的工作: https://github.com/jonataslaw/getx
需要完整示例、进阶中间件、GetConnect、国际化高级用法等 → 请直接访问上游 README 或本地 documentation/。
Libraries
- get
- GetX is an extra-light and powerful multi-platform framework. It combines high performance state management, intelligent dependency injection, and route management in a quick and practical way.
- get_animations/animations
- get_animations/extensions
- get_animations/get_animated_builder
- get_animations/index
- get_common/get_reset
- get_connect/connect
- get_connect/http/src/certificates/certificates
- get_connect/http/src/exceptions/exceptions
- get_connect/http/src/http
- get_connect/http/src/http/html/file_decoder_html
- get_connect/http/src/http/html/http_request_html
- get_connect/http/src/http/interface/request_base
- get_connect/http/src/http/io/file_decoder_io
- get_connect/http/src/http/io/http_request_io
- get_connect/http/src/http/mock/http_request_mock
- get_connect/http/src/http/request/http_request
- get_connect/http/src/http/stub/file_decoder_stub
- get_connect/http/src/http/stub/http_request_stub
- get_connect/http/src/http/utils/body_decoder
- get_connect/http/src/interceptors/get_modifiers
- get_connect/http/src/multipart/form_data
- get_connect/http/src/multipart/multipart_file
- get_connect/http/src/request/getx_request
- get_connect/http/src/response/client_response
- get_connect/http/src/response/getx_response
- get_connect/http/src/status/http_status
- get_connect/http/src/utils/utils
- get_connect/sockets/sockets
- get_connect/sockets/src/socket_notifier
- get_connect/sockets/src/sockets_html
- get_connect/sockets/src/sockets_io
- get_connect/sockets/src/sockets_stub
- get_core/get_core
- get_core/src/flutter_engine
- get_core/src/get_interface
- get_core/src/get_main
- get_core/src/log
- get_core/src/smart_management
- get_core/src/typedefs
- get_instance/get_instance
- get_instance/src/bindings_interface
- get_instance/src/extension_instance
- get_instance/src/lifecycle
- get_navigation/src/bottomsheet/bottomsheet
- get_navigation/src/dialog/dialog_route
- get_navigation/src/root/get_cupertino_app
- get_navigation/src/root/get_material_app
- get_navigation/src/root/get_root
- get_navigation/src/root/internacionalization
- get_navigation/src/router_report
- get_navigation/src/routes/circular_reveal_clipper
- get_navigation/src/routes/custom_transition
- get_navigation/src/routes/default_route
- get_navigation/src/routes/default_transitions
- get_navigation/src/routes/get_information_parser
- get_navigation/src/routes/get_route
- get_navigation/src/routes/get_router_delegate
- get_navigation/src/routes/get_transition_mixin
- get_navigation/src/routes/go_router_support
- get_navigation/src/routes/index
- get_navigation/src/routes/modules
- get_navigation/src/routes/new_path_route
- get_navigation/src/routes/observers/route_observer
- get_navigation/src/routes/page_settings
- get_navigation/src/routes/parse_route
- get_navigation/src/routes/route_middleware
- get_navigation/src/routes/route_report
- get_navigation/src/routes/router_outlet
- get_navigation/src/routes/test_kit
- get_navigation/src/routes/transitions_type
- get_navigation/src/routes/url_strategy/impl/io_url
- get_navigation/src/routes/url_strategy/impl/stub_url
- get_navigation/src/routes/url_strategy/impl/web_url
- get_navigation/src/routes/url_strategy/url_strategy
- get_navigation/src/routes/web_history_helper
- get_navigation/src/routes/web_history_helper_stub
- get_navigation/src/routes/web_history_helper_web
- get_navigation/src/snackbar/snackbar
- get_navigation/src/snackbar/snackbar_controller
- get_rx/get_rx
- get_rx/src/rx_stream/rx_stream
- get_rx/src/rx_typedefs/rx_typedefs
- get_rx/src/rx_types/rx_types
- get_rx/src/rx_workers/rx_workers
- get_rx/src/rx_workers/utils/debouncer
- get_state_manager/get_state_manager
- get_state_manager/src/rx_flutter/rx_getx_widget
- get_state_manager/src/rx_flutter/rx_notifier
- get_state_manager/src/rx_flutter/rx_obx_widget
- get_state_manager/src/rx_flutter/rx_ticket_provider_mixin
- get_state_manager/src/simple/get_controllers
- get_state_manager/src/simple/get_responsive
- get_state_manager/src/simple/get_state
- get_state_manager/src/simple/get_view
- get_state_manager/src/simple/get_widget_cache
- get_state_manager/src/simple/list_notifier
- get_state_manager/src/simple/mixin_builder
- get_state_manager/src/simple/simple_builder
- get_utils/get_utils
- get_utils/src/equality/equality
- get_utils/src/extensions/context_extensions
- get_utils/src/extensions/double_extensions
- get_utils/src/extensions/duration_extensions
- get_utils/src/extensions/dynamic_extensions
- get_utils/src/extensions/event_loop_extensions
- get_utils/src/extensions/export
- get_utils/src/extensions/int_extensions
- get_utils/src/extensions/internacionalization
- get_utils/src/extensions/iterable_extensions
- get_utils/src/extensions/num_extensions
- get_utils/src/extensions/string_extensions
- get_utils/src/extensions/widget_extensions
- get_utils/src/get_utils/get_utils
- get_utils/src/platform/platform
- get_utils/src/platform/platform_io
- get_utils/src/platform/platform_stub
- get_utils/src/platform/platform_web
- get_utils/src/queue/get_queue
- get_utils/src/widgets/optimized_listview