Good day everyone! I've got a doubt that sadly couldn't be found here.
Here is the deal: I'm building an application in MVVM architecture + Clean code, trying to separate the logic concepts of the screen into the controller that is going to be used to control the state of the screen.
The controller will be made of AsyncNotifierProvider, which state will return an AsyncValue with a custom object that mixes together lots of data obtained from different use cases.
A state example below :
part 'home_state.freezed.dart';
@freezed
class HomeState with _$HomeState {
const factory HomeState({
required List<AdvertisementDto> advertisements,
required List<ProductDto> firstPopularProducts,
required List<ProductDto> secondPopularProducts,
required AdvertisementDto specialOffer,
}) = _HomeState;
}
The thing is that I wanted to use the select() function that has its description here, to manage the screen's state rebuild separately to each field of the HomeState.
But it won't work in a situation where I want to handle the async state of the controller with the function when(), as the function when() should return different widgets for each situation (data, loading, and error), while the select() should return the specific value (in the case, the chosen field of the custom HomeState).
I've tried to use the new selectAsync(), which doesn't have documentation but just an issue saying about its implementation in this link, but sadly it is better fit to use it with FutureProvider or StreamProvider, as it returns the solved object from the future/stream, not having its own when() function to build each type of widget for each AsyncValue type. To simplify, with the AsyncValue, using selectAsync() on it just returns HomeState.
So I'm wondering if anyone knows how to handle each field of HomeState, without breaking the pattern of having a single Controller for the current Screen? Or should I make a separate Controller for each field of the HomeState, as all of them are async? The only solution that I came up with was to do this last option for a controller (AsyncNotifierProvider) to each field, but I wonder if this breaks the architecture's rules or not ...
I'm also asking this here as, in case there isn't any good solution for this situation, I'll try to ask for a feature of a special select() function for an AsyncValue at the Riverpod's GitHub.