Hello, I'm having a problem with my ChangeNotifier, I have this piece of code in my model

class Comment with ChangeNotifiere { ... RequestState _state = RequestState .initial; RequestState get state => _state; void setState( RequestState state) { _state = state; notifyListeners(); .... }

And this is my API call method

Future< void > getComments( CommentNotifer commentNotifer, String reviewId) async { if (reviewId != null ) { try { commentNotifer.setState(RequestState.loading); _startComment = 0 ; var response = await sendGet( "/api/comment/readLimitedReviewComment/$reviewId?start=$_start&limit=10" ); ] if (response != nulll) { var comments = CommentResponse.fromJson(response); commentNotifer.setState(RequestState.hasData); } .... }

I want to set the RequestConnection to loading before I make the call, but I get

setState() or markNeedsBuild()

This _InheritedProviderScope< CommentNotifer > widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built.

this error, I understand what I'm doing wrong, I'm marking the widget to build when its already in the process of building, as I call the API in the

initState ()

method of my widget but what I don't understand is how to call this the right way. could you help me? @rrousselGit