Skip to content

Commit b31e1a5

Browse files
committed
refactor: update photo manager service permissions and audio retrieval logic
1 parent f232f47 commit b31e1a5

2 files changed

Lines changed: 26 additions & 30 deletions

File tree

lib/src/core/services/photo_manager_service/photo_manager_service.dart

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ class PhotoManagerService {
7373
Future<void> requestPermission() async {
7474
final PermissionState result;
7575
try {
76-
result = _permissionState ?? await PhotoManager.requestPermissionExtend();
76+
result = _permissionState ??
77+
await PhotoManager.requestPermissionExtend(
78+
requestOption: const PermissionRequestOption(
79+
androidPermission: AndroidPermission(
80+
type: RequestType.common,
81+
mediaLocation: false,
82+
),
83+
),
84+
);
7785
} catch (_) {
7886
log('Failed to request permission!', name: 'PhotoManagerService');
7987
throw PermissionException();
@@ -98,27 +106,31 @@ class PhotoManagerService {
98106
throw PermissionException();
99107
}
100108

101-
final List<AssetEntity>? assets;
102109
try {
103110
final assetPaths = _assetPaths ??
104111
await PhotoManager.getAssetPathList(type: RequestType.audio);
105-
final recentAssetPath = assetPaths.isNotEmpty ? assetPaths[0] : null;
106-
assets = _assets ??
107-
await recentAssetPath?.getAssetListRange(
112+
113+
log('Found ${assetPaths.length} audio paths', name: 'PhotoManagerService');
114+
115+
if (assetPaths.isEmpty) {
116+
// No audio files found on device - return empty list instead of throwing
117+
log('No audio files found on device', name: 'PhotoManagerService');
118+
return [];
119+
}
120+
121+
final recentAssetPath = assetPaths[0];
122+
final assets = _assets ??
123+
await recentAssetPath.getAssetListRange(
108124
start: 0,
109125
end: 1000,
110126
);
111-
} catch (_) {
112-
log('Failed to get audio assets!', name: 'PhotoManagerService');
127+
128+
log('Retrieved ${assets.length} audio assets', name: 'PhotoManagerService');
129+
return assets;
130+
} catch (e) {
131+
log('Failed to get audio assets: $e', name: 'PhotoManagerService');
113132
throw GetAudioException();
114133
}
115-
116-
if (assets == null) {
117-
log('Failed to get audio assets!', name: 'PhotoManagerService');
118-
throw GetAudioException();
119-
}
120-
121-
return assets;
122134
}
123135

124136
/// Gets the video assets.

pubspec.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,6 @@ packages:
365365
description: flutter
366366
source: sdk
367367
version: "0.0.0"
368-
freezed:
369-
dependency: "direct dev"
370-
description:
371-
name: freezed
372-
sha256: "59a584c24b3acdc5250bb856d0d3e9c0b798ed14a4af1ddb7dc1c7b41df91c9c"
373-
url: "https://pub.dev"
374-
source: hosted
375-
version: "2.5.8"
376368
freezed_annotation:
377369
dependency: "direct main"
378370
description:
@@ -938,14 +930,6 @@ packages:
938930
description: flutter
939931
source: sdk
940932
version: "0.0.0"
941-
source_gen:
942-
dependency: transitive
943-
description:
944-
name: source_gen
945-
sha256: "35c8150ece9e8c8d263337a265153c3329667640850b9304861faea59fc98f6b"
946-
url: "https://pub.dev"
947-
source: hosted
948-
version: "2.0.0"
949933
source_map_stack_trace:
950934
dependency: transitive
951935
description:

0 commit comments

Comments
 (0)