So I need to get the result from the following provider:
ExpansionTile(
onExpansionChanged: (isExpanding) {
if (isExpanding) {
final result = ref.read(leaveDetailsProvider(value.items[index].id));
result.when(data: (value) {
logger.i(value);
}, error: (error, trace) {
logger.e(error);
}, loading: () {
logger.i('Loading...');
});
}
}
);
ref.read()
always return loading state if not initialized first and it’s expected. On the other hand, leaveDetailsProvider
accepts a param so I didn’t initialize it using ref.watch()
inside build
method because that means I will have to run ref.watch()
using every param available which doesn’t make sense.
What is the solution, then? I know something is wrong but I can’t find the answer so far.