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:
}
},
),
);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With