GetX是Flutter一个超轻和强大的解决方案。它结合了高性能的状态管理、智能依赖注入和路由管理,快速而实用。
- 路由管理
1.1.直接使用
Get.to(GetControllerPage());
1.2.路由命名
第一步:通过引入get框架,在应用最外层包裹GetMaterialApp组件,创建路由列表
import 'package:get/get.dart';
runApp(GetMaterialApp(
home: const MyApp(),
getPages: AppPages.routes,
));
第二步:配置路由列表
class AppPages {
static final routes = <GetPage>[
GetPage(
name: AppRoutes.GET_NORAML,
page: () => const GetControllerPage(),
binding: GetIndexBinding()),
GetPage(
name: AppRoutes.OBS_GET_NORAML,
page: () => const ObsGetControllerPage(),
binding: ObsGetIndexBinding()),
];
}
定义静态常量作为路由命名参数
abstract class AppRoutes {
static const GET_NORAML = '/getNoraml';
static const OBS_GET_NORAML = '/getObsNoraml';
}
第三步:使用静态命名作为参数进行跳转到GetControllerPage
Get.toNamed(AppRoutes.GET_NORAML);