Can not disable camera permission in PermissionHandler

Viewed 452

I have been searching for this for a while, in my program, I use permission_handler to enable camera permission. However, I also want my users to be able to disable the camera permissions programmatically.

Here is the code:

                 child: SwitchListTile(
                    contentPadding: EdgeInsets.all(0),
                    value: isCameraAllowed,
                    onChanged: (value) async {
                      if(value){
                        var isGranted = await Permission.camera.request().isGranted;
                        if(isGranted){
                          setState(() {
                            isCameraAllowed = value;
                          });
                        }
                      }
                    },
                    title: Row(
                      children: [
                        Text(S.current.privacySettingsPageActiveDeactive),
                        Spacer(),
                        Icon(isCameraAllowed ? Icons.videocam : Icons.videocam_off)
                      ],
                    ),
                  )

I use SwichListTile to indicate either the permission is on or off, so when the user turns tile to on, I am able to ask for permission and update it however when the user wants to turn off the permission, I could not find a way to do it. Can anyone help with it?

2 Answers

Currently, no plugin or package in Flutter supports this feature. What these current plugins/packages do is that they call a native feature to request camera permission.

So, if I request for Camera permission, a request goes to the native handler that checks if the permission is granted or not. If not, then it requests for the permission.

You cannot enable or disable an permission directly from the app. It requires a call to the native handler.

You could not find a way to do it. Because there is no way to ask again for granted permissions. The user must change the permission from the settings of the app.

Related