I am using below method to check whether Camera permission is granted or not:
//Global variable
int cameraPermission = -1;
Future<void> checkCameraPermission() async {
cameraPermissionStatus = await Permission.camera.status;
print(">>>>>>>>>>>>>>>>>>>>>>>>>>\ncamera permission >> " +
cameraPermissionStatus.name);
if (cameraPermissionStatus.name == "granted") {
cameraPermission = 1;
scheduleTimeout(4 * 1000);
} else if (cameraPermissionStatus.name == "denied") {
cameraPermission = 2;
} else {
cameraPermission=0;
}
setState(() {});
}
calling above method in initState()
inside addPostFrameCallback
Reflecting view in build method as below:
return Column(
children: [
cameraPermission==1
? Expanded(flex: 2, child: buildCameraPreview())
: cameraPermission==2
? Container(
child: InkWell(
onTap: () async {
await Permission.camera.request();
},
child: Padding(
padding: EdgeInsets.only(top: 200.h),
child: Text(
"Tap here to grant Camera Permission")),
))
: cameraPermission==0
? Center(
child: InkWell(
onTap: () {
openAppSettings();
},
child: Text(
"Tap here to grant Camera permission\nfrom application Settings"),
))
: Container(),
The Issue is by default is displays "denied" view (cameraPermission==2) which is okay, But since I have called checkCameraPermission method in init inside addPostFrameCallback,
It should reflect once I grant or allow camera permission from opened permission dialog but it not reflecting view. After going back to previous screen and coming back its working.
What might be the issue? Thanks in advance.
cameraPermission
, and you did not updated thecameraPermission
variable once the user has granted the access. Try settingcameraPermission
to 1 inside setState. Else try callingawait Permission.camera.request();
sindie theaddPostFrameCallBack
.