flutter_notification_permissions icon indicating copy to clipboard operation
flutter_notification_permissions copied to clipboard

Wait for user response to requestNotificationPermissions

Open dluksza opened this issue 5 years ago • 5 comments

Would it be possible to wait with Future resolution of requestNotificationPermissions() until user has granted or denied notification permission?

dluksza avatar Sep 04 '19 17:09 dluksza

I have this question as well how can we listen to an update from the user when the permission dialog pops up, how could we know whether permission was granted or denied

droidluv avatar Sep 30 '19 09:09 droidluv

@droidluv, I've forked flutter_local_notifications in order to add this functionality, you can use my fork https://github.com/dluksza/flutter_local_notifications

dluksza avatar Sep 30 '19 17:09 dluksza

Hey all!

Sorry for taking so long in replying.

Could you try version 0.4.3 and let me know if that fixes the issue?

If not could you please elaborate a little more?

Vanethos avatar Oct 07 '19 16:10 Vanethos

I used 0.4.3, and it still does not seem to wait until user comes back from the setting page.

One workaround that I found is to use flutter's [WidgetsBindingObserver](https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html).

Basically, you can observe app lifecycle changes, and should look for AppLifecycleState.resumed state. When this state is triggered, that likely means that the user has returned back from 'Setting' page, and you can fetch permission again to see if the value has been updated.

class SomeWidgetState extends State<SomeWidget> {
...

@override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  Future didChangeAppLifecycleState(AppLifecycleState state) async {
    // user coming back from settings page (notification change).
    if (state == AppLifecycleState.resumed) {
        NotificationPermissions.getNotificationPermissionStatus().then((permission) {
           ...
        });
    }
   ...
}

cielo avatar Dec 18 '19 06:12 cielo

Any news on this ?

Nico04 avatar Mar 12 '22 09:03 Nico04