Ollie
Ollie

Reputation: 664

listen to device notification permission using Flutter notification_permissions package

I am using the Flutter notification_permissions package.

I can retrieve the device notification permission status asynchronously by calling:

PermissionStatus p = await NotificationPermissions.getNotificationPermissionStatus()

However, I do not want to do this just once. I want to listen to the notification status as a stream, so that when it changes I can respond accordingly in my UI.

I tried the following:

NotificationPermissions.getNotificationPermissionStatus().asStream().listen((PermissionStatus s) {
    print('Notification permissions: $s');   
}

However, this stream does not emit events when I change the notification settings on the device.

How can I achieve this?

Upvotes: 3

Views: 3152

Answers (1)

Ollie
Ollie

Reputation: 664

I have achieved my desired functionality by creating a stateful widget that listens to the AppLifecycleState. I then call my async function whenever the app resumes to check the status of notification settings.

More info here: Flutter: Update Widgets On Resume?

Upvotes: 4

Related Questions