9

I am trying to show a pop up for requesting notification permission. I have tried using permission_handler package but for notification and bluetooth, it will show no dialog. Is there any other way to show dialog to ask notification permission ?

3
  • I know it doesn't help but I'm having the same problem on Android 13. Have you found a solution? Commented Sep 17, 2022 at 16:15
  • Hi @TomaszCz. I haven't found any solution yet for my case and still looking for it until now Commented Sep 19, 2022 at 1:36
  • 1
    I just try the solution from @Abdelrahman Tareq today and it works but for pop up notification we should do it manually Commented Sep 19, 2022 at 1:57

3 Answers 3

5

Using permission_handler package, the following code will pop up a dialog requesting the user for notification permission:

Future<void> requestNotificationPermissions() async {
   final PermissionStatus status = await Permission.notification.request();
   if (status.isGranted) {
      // Notification permissions granted
   } else if (status.isDenied) {
      // Notification permissions denied
   } else if (status.isPermanentlyDenied) {
      // Notification permissions permanently denied, open app settings
      await openAppSettings();
   }
}

You may call the function inside the main function or anywhere you see fit.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot after lib update to latest it working like charm.
3

You can use notification_permission

2 Comments

Hi I just try it today and so far it works fine, thank you very much @Abdelrahman Tareq for your help
You're welcome my friend
3

I got the same issue that it didn't show the pop up. Here is my solution:

  • iOS:

In Podfile, I change value from 0 into 1 for permissions that I need to use. For ex:

...
post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    # YOUR CUSTOM TARGET CODE HERE.
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        ## dart: PermissionGroup.calendar
        'PERMISSION_EVENTS=0',
   
        ## dart: PermissionGroup.notification
        'PERMISSION_NOTIFICATIONS=1',

        ## dart: PermissionGroup.bluetooth
        'PERMISSION_BLUETOOTH=1',
      ]
    end
  end
end
  • Android:

In android -> app -> build.gradle, I set 33 for targetSdkVersion. For ex:

...
android {
    ...

    defaultConfig {
        ...
        minSdkVersion 21 // flutter.minSdkVersion
        targetSdkVersion 33 // flutter.targetSdkVersion
        ...
    }

    ...
}
...

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.