Flutter Permission Handler not re-asking for permission if already denied

4,666

As noted here, you cannot request permission again on iOS, after it was denied. You have to take the user to the Settings app and let them give your app the permission manually.

App Settings is a great package for this, especially their openAppSettings method.

Requesting permission after it was denied

Share:
4,666
TJMitch95
Author by

TJMitch95

Updated on December 24, 2022

Comments

  • TJMitch95
    TJMitch95 over 1 year

    I am trying to access the microphone of the users device, I have managed to integrate the permissions_handler package somewhat successfully. When I clicked the mic icon the request permission message popped up as expected but I pressed deny to deal with that scenario but now, when I click the mic icon no message pops up because I have already denied permission. My question is, how I can re-ask user for their permission if they haven't granted it before? Here is my code:

    import 'package:flutter/material.dart';
    import 'package:permission_handler/permission_handler.dart';
    
    class InsideLeft extends StatefulWidget {
      @override
      _InsideLeftState createState() => _InsideLeftState();
    }
    
    class _InsideLeftState extends State<InsideLeft> {
      @override
      Widget build(BuildContext context) {
        return Container(
    
          child: GestureDetector(
            child: Icon(Icons.mic),
            onTap: () async {
              var status = await Permission.microphone.status;
              switch (status) {
                case PermissionStatus.granted:
                  print('Granted');
                  break;
                case PermissionStatus.denied:
                  print('denied');
                  await Permission.microphone.request();
                  break;
                case PermissionStatus.restricted:
                  print('restricted');
                  break;
                case PermissionStatus.undetermined:
                  print('undetermined');
                  break;
                case PermissionStatus.permanentlyDenied:
                  print('Permanently denied');
                  break;
                default:
              }
            },
          ),
        );
      }
    }