class PortfolioHomeCubit extends Cubit<PortfolioHomeState> {
PortfolioHomeCubit() : super(PortfolioHomeState());
final apiService = ApiService();
Future<void> _onFetchContent() async {
final cache = apiService.cache;
final homeContent = cache.portfolioHomeContent;
emit(state.copyWith(portfolioHomeContent: homeContent));
final response = await apiService.getData();
final content = response.portfolioHomeContent;
emit(state.copyWith(portfolioHomeContent: content));
}
}
final portfolioHomeContentProvider =
BlocProvider<PortfolioHomeCubit, PortfolioHomeState>(
((ref) => PortfolioHomeCubit().._onFetchContent()),
);
This code works just fine but I am confused. If the _onfetch function retrieves cached data from the ApiService object why do fire another API request? Is it because the cache can be null? and why will it be null when an api request is already fired in the ApiService and saved to the cache variable?
Just incase, this is river_bloc