7

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:
          }
        },
      ),
    );
  }
}
TJMitch95
  • 421
  • 3
  • 7
  • 23
  • you can use the openSettings(); provided by the permission handler packaget which opens the settings of your app and ask the user to allow the permission , that's the only way around if the user denies permission – basudev nayak Jan 27 '21 at 13:35

1 Answers1

8

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

Aleksandar
  • 3,558
  • 1
  • 39
  • 42