the question simlar on Flutter Provider setState() or markNeedsBuild() called during build
following the question , i have implemented the consume like these one
....
fetchEvents(){
final modelBrainR = context.read<ModelBrain>();
modelBrainR.fetchEvents();
}
...
...
...
child: Consumer<ModelBrain>(
builder: (context, modelData, child) {
if(modelData.action == 're_fetch'){ // here i need to trigger to load a new data again
fetchEvents() // and i would like to change loading state to EventState.Loading // this just make sure of data // and maybe can be infinity loading but in the real case its just one time
}
})
the conslusion of the question [mention again]
EventLoadingStatus _eventLoadingStatus = EventLoadingStatus.Loading;
...
Future<void> fetchEvents(String email) async {
List<Event> events = await EventService().getEventsByUser(email);
_events.clear();
_events.addAll(events);
_eventLoadingStatus = EventLoadingStatus.Loaded;
notifyListeners();
}
so i still need to change _eventLoadingStatus
to EventLoadingStatus.Loading
; whenever modelData.action == 're_fetch'
in consumer ...
or am i missing on implementation ?
its work only on outside of consumer for example i have appBar thats use InkWel / gesture detector.
// outside of consumer
AnimationClick(
function: () {
context.read<ModelBrain>().eventLoading();
fetchEvents();
},
)
class ModelBrain with ChangeNotifier {
...
Future<void> eventLoading() async {
_eventState = EvenState.Loading;
notifyListeners();
}
...
}