downloadMedia static method
Implementation
static Future<bool> downloadMedia({required String url}) async {
try {
if (url.isEmpty) {
throw EticonDownloadError(error: 'Url is empty');
}
int indexOfExtr = url.lastIndexOf('.');
String fileFormat = url.substring(indexOfExtr);
if (fileFormat.isEmpty) {
throw EticonDownloadError(error: 'File format not defined');
}
if (fileFormat == '.mp4' ||
fileFormat == '.mov' ||
fileFormat == '.avi' ||
fileFormat == '.wmv' ||
fileFormat == '.3gp' ||
fileFormat == '.3gpp' ||
fileFormat == '.mkv' ||
fileFormat == '.flv') {
if (!(await _requestPermission(Platform.isAndroid ? Permission.storage : Permission.photos))) {
return false;
}
await GallerySaver.saveVideo(url);
} else {
if (!(await _requestPermission(Platform.isAndroid ? Permission.storage : Permission.photos))) {
return false;
}
await GallerySaver.saveImage(url);
}
} catch (error) {
throw EticonDownloadError(error: 'Media download problem, error: $error');
}
return true;
}