download static method

Future<void> download({
  1. required String url,
  2. required String savePath,
  3. dynamic onError(
    1. ApiException error
    )?,
  4. dynamic onReceiveProgress(
    1. int value,
    2. int progress
    )?,
  5. required Function onSuccess,
})

download file

Implementation

static Future<void> download({
  required String url,
  required String savePath,
  Function(ApiException error)? onError,
  Function(int value, int progress)? onReceiveProgress,
  required Function onSuccess,
}) async {
  try {
    await _dio.download(
      url,
      savePath,
      options: Options(
        receiveTimeout: const Duration(seconds: _timeoutInSeconds),
        sendTimeout: const Duration(seconds: _timeoutInSeconds),
      ),
      onReceiveProgress: onReceiveProgress,
    );
    onSuccess();
  } catch (error) {
    onError?.call(ApiException(url: url, message: "DOWNLOAD_EXCEPTION"));
  }
}