downloadChange function

Future<List<int>> downloadChange(
  1. String image,
  2. void callback(
    1. String
    )
)

Implementation

Future<List<int>> downloadChange(
  String image,
  void Function(String) callback,
) async {
  final dio = Dio();
  final response = await dio.get<dynamic>(
    image,
    onReceiveProgress: (count, total) {
      if (total != -1) {
        callback.call('${(count / total * 100).toStringAsFixed(0)}}%');
      }
    },
    options: Options(
      responseType: ResponseType.bytes,
      followRedirects: false,
      validateStatus: (status) {
        return (status ?? 0) < 500;
      },
    ),
  );

  if (response.statusCode == 200) {
    return response.data;
  } else {
    stdout.writeln(response.statusMessage);
    return [];
  }
}