fetchAssets method
Implementation
Future<List<AssetEntity>> fetchAssets({bool refresh = false}) async {
if (refresh) _pageIndex = 0;
final state = await PhotoManager.requestPermissionExtend();
if (state == PermissionState.authorized) {
try {
final assets = (await value.path?.getAssetListPaged(page: _pageIndex, size: _pageSize)) ?? [];
final updatedAssets = refresh ? assets : [...value.assets, ...assets];
++_pageIndex;
value = value.copyWith(fetchStatus: FetchStatus.completed, assets: updatedAssets);
} catch (e) {
debugPrint('Exception fetching assets => $e');
value = value.copyWith(fetchStatus: FetchStatus.error, error: e.toString());
}
} else {
value = value.copyWith(fetchStatus: FetchStatus.unauthorised);
}
return value.assets;
}