【发布时间】:2021-04-01 16:28:04
【问题描述】:
我有一个由LectureRepositoryImpl 实现的抽象类LectureRepository。 LectureRepositoryImpl 初始化 SharedPreferences sharedPreferences 与
LectureLocalDataSourceImpl({@required this.sharedPreferences})
现在我想使用 Riverpod 访问存储库,所以我这样做了:
FutureProvider<LectureLocalDataSource>(
(ref) async {
return LectureLocalDataSourceImpl(sharedPreferences: await SharedPreferences.getInstance());
},
);
但现在在lectureRepositoryProvider 中,我阅读了lectureLocalDataRepositoryProvider 我在值localDataSource 中得到了一个AsyncValue,我无法在此处分配它:
final lectureRepositoryProvider = FutureProvider<LectureRepository>((ref) async {
final localDataSource = ref.read(lectureLocalDataRepositoryProvider);
return LectureRepositoryImpl(localDataSource: localDataSource);
});
我应该如何处理 AsyncValue?
【问题讨论】:
标签: flutter asynchronous dependency-injection provider riverpod