I have a notification service which is a change notifier. When the service recieves a notification it notifies all listners. I want to display a dialog when the listners get notified. So I do the following in my build method
Consumer<NotificationService>(
builder: (BuildContext context, NotificationService notificationNotifier, _) {
if (notificationNotifier.hasNotifications)
_showNotification(context, notificationNotifier.popNotification());
return Scaffold(
This is the shownotification method
Future<dynamic> _showNotification(BuildContext context, NotificationModel notification) async {
try {
print(notification.title);
await PlatformAlertDialog(
notification.title,
notification.body,
).show(context);
} on UserFriendlyException catch (error) {
await PlatformAlertDialog(
error.title,
error.message,
).show(context);
}
}
So but this throws an error because I want to build the dialog while I am building Unhandled Exception: setState() or markNeedsBuild() called during build.
I do like using the change notifier provider. So how could I make this work?