全局注册

1
2
3
4
5
6
7
void main() async {
await GetStorage.init();
await Get.put(DeviceController(), permanent: true).ensureInitialized();
Get.lazyPut(() => AuthController());
Get.lazyPut(() => LoginDialogController(), fenix: true);
runApp(const MainApp());
}

fenix参数是让这个控制器销毁后恢复之前的状态,取了一个很好的名字:凤凰

页面注入

通过binding可以注入,这样的好处是在页面打开时候他会自动创建,等页面退出他会自动销毁

1
2
3
4
5
6
7
8
GetPage(
name: AppRoutes.talentApply,
page: () => const TalentApplyScreen(),
binding: BindingsBuilder(() {
Get.lazyPut<TalentApplyController>(() => TalentApplyController());
}),
transition: Transition.native,
),