I'm calling one of the ChangeNotifier functions from an initState() method and the notifyListener() call inside the function is throwing
setState() or markNeedsBuild() called during build. exception
void initState(){
Provider.of<MessengerRepository>(context, listen: false).setUnreadCount(0);
super.initState();
}
class MessengerRepository with ChangeNotifier {
int unreadCount;
void setUnreadCount(int value){
unreadCount = value;
notifyListeners();
}
I need to call the notifyListener() inside setUnreadCount() as I'm calling the setUnreadCount() function in multiple places during the execution. So can't remove the notifyListener() only inside initState().
Using provider version 4.0.4