-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Can we access your project?
- I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.
Current Behavior
Hi,
I'd like to report two related issues:
Issue 1
permissions_util.dart
In the permissions_util.dart file, the requestPermission function is unnecessarily requesting permission twice on Android devices.
Future<void> requestPermission(Permission setting) async {
if (setting == Permission.photos && isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt <= 32) {
await Permission.storage.request();
} else {
await Permission.photos.request();
}
}
await setting.request();
}
Issue 2
permissions_util.dart
In the permissions_util.dart file, for devices with sdk <= 32, the getPermissionStatus function is incorrectly checking for Permission.photos instead of Permission.storage.
Future<bool> getPermissionStatus(Permission setting) async {
final status = await setting.status;
return kPermissionStateToBool[status]!;
}
Expected Behavior
Issue 1
To fix the issue 1, we may rewrite the code as follows
Future<void> requestPermission(Permission setting) async {
if (setting == Permission.photos && isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt <= 32) {
await Permission.storage.request();
} else {
await Permission.photos.request();
}
} else {
await setting.request();
}
}
Or
Future<void> requestPermission(Permission setting) async {
if (isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (setting == Permission.photos && androidInfo.version.sdkInt <= 32) {
setting = Permission.storage;
}
}
await setting.request();
}
Issue 2
To fix the issue 2, we may rewrite the code as follows
Future<bool> getPermissionStatus(Permission setting) async {
if (isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (setting == Permission.photos && androidInfo.version.sdkInt <= 32) {
setting = Permission.storage; // Adjust to storage for older Android versions
}
}
final status = await setting.status;
return kPermissionStateToBool[status]!;
}
Temporary workaround until fix is provided
Create an action and call this action instead of default conditional check Photo Library before requesting Photo Library permission.
// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:permission_handler/permission_handler.dart'; // Import the permission handler package
import 'package:device_info_plus/device_info_plus.dart'; // Import the device info package
const kPermissionStateToBool = {
PermissionStatus.granted: true,
PermissionStatus.limited: true,
PermissionStatus.denied: false,
PermissionStatus.restricted: false,
PermissionStatus.permanentlyDenied: false,
};
Future<bool> photoStoragePermissionStatus() async {
// Initialize the setting variable to Permission.photos
Permission setting = Permission.photos;
if (isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt <= 32) {
setting = Permission
.storage; // Map photos to storage for older Android versions
}
}
final status = await setting.status;
return kPermissionStateToBool[status]!;
}
Steps to Reproduce
Project Setup:
Create a new Flutter project named TestPermissions.
Modify App Permissions:
Navigate to App Settings > Permissions.
Add the text "Provide access to photo library" under the Photo Library permission description.
Create a User Interface:
Create a new page in your Flutter project.
Add a button to the page and label it "Photo Library Permission".
Configure Button Action:
Implement an action for the button to check the Photo Library permission conditionally.
The action should perform the following:
Check the status of the Photo Library permission.
If the permission status returns false (which may occur due to the issue described), request access to the Photo Library.
Handle Permission Status:
Note that the permission status might incorrectly return false even if access is granted because of the issue mentioned.
Reproducible from Blank
- The steps to reproduce above start from a blank project.
Bug Report Code (Required)
none
Visual documentation
Loom videos
Backend
https://www.loom.com/share/3816359fe20a46dd8830cc96600b95f3?sid=bb1b1ff1-06c7-4b9a-a8a8-1acc99c6e384
Frontend
https://www.loom.com/share/6d6023413af94768bd12af77babc76a2?sid=bd77ba44-c3fa-42ba-b6f7-63fd01199ce7
Link to project
https://app.flutterflow.io/project/test-permissions-mplmmg?tab=uiBuilder&page=HomePage
Environment
- FlutterFlow version: v4.1.85+
- Platform: Android
- Operating system and version affected: Android 11, SDK 30Additional Information
No response