123456789101112131415161718192021222324252627282930313233343536373839 |
- import 'dart:typed_data';
- import 'package:dio/dio.dart' as dio;
- import 'package:fis_common/logger/logger.dart';
- class VidFileDownloadCancel extends dio.CancelToken {}
- typedef VidFileDownloadProgressCallback = void Function(int count, int total);
- class VidFileDownloader {
- static dio.Dio? _httpClient;
- static Future<Uint8List?> download(
- String url, {
- VidFileDownloadCancel? cancelToken,
- VidFileDownloadProgressCallback? onReceiveProgress,
- }) async {
- try {
- _httpClient ??= dio.Dio(
- dio.BaseOptions(
- responseType: dio.ResponseType.bytes,
- sendTimeout: 1 * 1000,
- receiveTimeout: 10 * 1000,
- ),
- );
- final response = await _httpClient!.get(
- url,
- cancelToken: cancelToken,
- onReceiveProgress: onReceiveProgress,
- );
- final bytes = response.data as Uint8List;
- return bytes;
- } catch (e) {
- logger.e("VidFileDownloader call download error", e);
- return null;
- }
- }
- }
|