【发布时间】:2023-01-27 14:34:08
【问题描述】:
我正在尝试将 floor 库与 get_it 库一起使用来简化调用
这个库的简单实现是:
final sl = GetIt.instance;
Future<void> init() async {
/// database
sl.registerLazySingletonAsync<AppDatabase>(
() => $FloorAppDatabase.databaseBuilder('app_database.db').build());
/// http client
sl.registerLazySingleton<ApiService>(
() => NetworkModule().getHttpProvider().getService());
/// call dao
sl.registerLazySingletonAsync<UserDao>(
() async => (await sl.getAsync<AppDatabase>()).userDao);
在 main() 函数中我调用:
等待 sl.init();
但我得到错误:
You tried to access an instance of UserDao that is not ready yet
'package:get_it/get_it_impl.dart':
package:get_it/get_it_impl.dart:1
Failed assertion: line 404 pos 9: 'instanceFactory.isReady'
我的代码有什么问题?? 谢谢
我提到了这个答案 https://stackoverflow.com/questions/56497896/make-a-simple-single-instanse-class-as-database-helper
【问题讨论】:
-
同样在这里。你找到什么了吗?
标签: database flutter sqlite flutter-floor get-it