Skip to content

Commit

Permalink
TW-140: Setup and create PermissionHandlerService
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Jun 16, 2023
1 parent c19f14a commit 20d0012
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ post_install do |installer|
'PERMISSION_MICROPHONE=1',
## dart: PermissionGroup.contacts
'PERMISSION_CONTACTS=1',
## dart: PermissionGroup.camera
'PERMISSION_CAMERA=1',
## dart: PermissionGroup.photos
'PERMISSION_PHOTOS=1'
]
end
end
Expand Down
52 changes: 52 additions & 0 deletions lib/utils/voip/permission_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dart:io';
import 'package:permission_handler/permission_handler.dart';

class PermissionHandlerService {
static final PermissionHandlerService _instance = PermissionHandlerService._internal();

factory PermissionHandlerService() {
return _instance;
}

PermissionHandlerService._internal();


Future<PermissionStatus> requestPermissionForPhotoActions() {
if (Platform.isIOS) {
return _handlePhotosPermissionIOSAction();
} else {
return _handlePhotosPermissionAndroidAction();
}
}

Future<PermissionStatus> _handlePhotosPermissionIOSAction() async {
final currentStatus = await Permission.photos.status;
return _handlePermission(currentStatus);
}

Future<PermissionStatus> _handlePhotosPermissionAndroidAction() async {
final currentStatus = await Permission.storage.status;
return _handlePermission(currentStatus);
}


Future<PermissionStatus> _handlePermission(PermissionStatus currentStatus) async {
switch (currentStatus) {
case PermissionStatus.denied:
case PermissionStatus.limited:
final newStatus = Platform.isIOS
? await Permission.mediaLibrary.request()
: await Permission.storage.request();
return newStatus.isGranted ? PermissionStatus.granted : newStatus;

case PermissionStatus.granted:
case PermissionStatus.restricted:
case PermissionStatus.permanentlyDenied:
return currentStatus;
}
}

void goToSettingsForPermissionActions() {
openAppSettings();
}
}
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import just_audio
import macos_ui
import package_info_plus_macos
import path_provider_foundation
import photo_manager
import record_macos
import share_plus_macos
import shared_preferences_macos
Expand Down Expand Up @@ -52,6 +53,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PhotoManagerPlugin.register(with: registry.registrar(forPlugin: "PhotoManagerPlugin"))
RecordMacosPlugin.register(with: registry.registrar(forPlugin: "RecordMacosPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Expand Down

0 comments on commit 20d0012

Please sign in to comment.