Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:
          }
        },
      ),
    );
  }
}
like image 761
TJMitch95 Avatar asked Sep 20 '20 19:09

TJMitch95


1 Answers

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

like image 68
Aleksandar Avatar answered Oct 28 '22 14:10

Aleksandar