我正在尝试使用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.初始化();
但我得到错误:
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
1条答案
按热度按时间r7xajy2e1#
使用
dependsOn
参考www.example.com并链接其每个模块。https://pub.dev/packages/get_it#automatic-using-dependson and chaining that its each module.例如: