say*_*bir 1 flutter flutter-getx
我在我的项目中使用 getx,我有一个 mainBianding 页面:
\nclass MainBinding implements Bindings {\n @override\n Future<void> dependencies() async {\n Get.putAsync<HiveService>(() => HiveService().init(), permanent: true);\n Get.lazyPut<HomeController>(\n () => HomeController(\n\n dbclient: Get.find<HiveService>()),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我有一个用于初始化 Hive 的 GETXService
\nclass HiveService extends GetxService {\n late Box<Model> vBox;\n\n Future<HiveService> init() async {\n final appDocumentDirectory =\n await path_provider.getApplicationDocumentsDirectory();\n Hive\n ..init(appDocumentDirectory.path)\n ..registerAdapter<Model>(ModelAdaptor())\n\n return this;\n }\nRun Code Online (Sandbox Code Playgroud)\n午餐后,App HomePage 和 HomeController 将启动,但我收到此错误:
\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following message was thrown building Builder:\n"HiveService" not found. You need to call "Get.put(HiveService())" or\n"Get.lazyPut(()=>HiveService())"\nThe relevant error-causing widget was:\n ScrollConfiguration\nRun Code Online (Sandbox Code Playgroud)\n因为 Hive 服务是一个 future ,它有一个延迟加载,但我Future<void> dependencies() async在这个绑定类上使用了。我必须如何等待才能确保 HiveService 完全加载并在主页加载之后?\n我正在使用 MainBinding Inside GetMaterialApp;
Future main() async {\n await MainBinding().dependencies();\n ...\n\n runApp(MyApp()\n return GetMaterialApp(\n debugShowCheckedModeBanner: false,\n useInheritedMediaQuery: true,\n locale: DevicePreview.locale(context),\n theme: ThemeData(\n primarySwatch: Colors.blue,\n ),\n initialRoute: Routes.HOME,\n getPages: AppPages.pages,\n initialBinding: MainBinding(),\nRun Code Online (Sandbox Code Playgroud)\n
测试这个
await Get.putAsync<HiveService>(() => HiveService().init(), permanent: true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3081 次 |
| 最近记录: |