How to detect permission dialog is denied by user

201

Add permission_handler: ^6.1.1 to you pubspec file

import it

import 'package:permission_handler/permission_handler.dart';

in you landing page or main.dart try calling this bellow functoin

bool storagePer = false;
    void storageCheck() async {
      var status = await Permission.storage.status;
      if (!status.isGranted) {
        await Permission.storage.request();
        storagePer = true;
        print('per: $storagePer');
      }
    }

To check if you have permission or not, use status.isGranted if it return true => permissionGranted else denied

to request permition use this await Permission.storage.request();

Share:
201
Deepak Sharma
Author by

Deepak Sharma

Updated on December 29, 2022

Comments

  • Deepak Sharma
    Deepak Sharma over 1 year

    I am implementing take pictures from galley in my app, for which I am adding storage permission. And I am requesting the permission from user using permission_handler package. And it is working perfectly in Android because it manages user state like permanently denied etc. But the main issue in the iOS in which either user deny or allow always shows user granted permission(Means always providing the status == granted)

    Please help if someone have same issue or I am doing anything wrong.

    Thank you.

  • Deepak Sharma
    Deepak Sharma about 3 years
    yes, you are right "Aditya kontikal", I am using it the same way. And it is working fine for android but for iOS giving the only status.isGranted(either user deny or allow the permission)
  • Deepak Sharma
    Deepak Sharma about 3 years
    Thank you, I found the solution, in iOS instead of storage permission I changed it to photos: - if (Platform.isIOS) { status = await Permission.photos.request(); } else if (Platform.isAndroid) { status = await Permission.storage.request(); }