download method
Future<Either<BaseException, String> >
download(
- String path, {
- Map<
String, dynamic> ? params, - OnProgressFunction? onProgress,
- RequestEnum type = .get,
- required Future<
String> saver(- Uint8List bytes
Implementation
Future<Either<BaseException, String>> download(
String path, {
Map<String, dynamic>? params,
OnProgressFunction? onProgress,
RequestEnum type = .get,
required Future<String> Function(Uint8List bytes) saver,
}) async {
try {
final options = Options(
responseType: ResponseType.bytes,
headers: {
'accept': '*/*',
'Content-Type': 'application/json',
},
);
final response = await switch (type) {
.get => _dio.get(
path,
queryParameters: params,
options: options,
onReceiveProgress: (received, total) => onProgress?.call(received / total),
),
.post => _dio.post(
path,
data: params,
options: options,
onReceiveProgress: (received, total) => onProgress?.call(received / total),
),
};
return Right(await saver(Uint8List.fromList(response.data)));
} catch (err, s) {
return ErrorHandler.fromError(err, stackTrace: s);
}
}