delete method Null safety
- MediaAsset asset
Deletes the asset. The asset cannot be used anymore afterwards. For local assets the file will be deleted, for remote assets the asset will be deleted from the CMS.
Implementation
Future<void> delete(MediaAsset asset) async {
if (asset.location == MediaAssetLocation.local) {
await File(asset.url).delete();
return;
}
final gqlQueryString = '''
mutation DeleteAsset {
deleteUpload(id: ${asset.id})
)
}
''';
try {
final queryResult = await graphQLClient.mutate<void>(MutationOptions(
document: gql(gqlQueryString),
));
if (queryResult.hasException) {
logger?.e(queryResult.exception.toString());
return;
}
return;
} catch (e, stackTrace) {
logger?.e('Could not delete media asset from repository', e, stackTrace);
return;
}
}