downloadWithProgress method Null safety

Future<Uint8List?> downloadWithProgress(
  1. String url
)

Implementation

static Future<Uint8List?> downloadWithProgress(String url) async {
  if (url.contains("youtube") || url.contains("youtu.be")) {
    ModernFormProgressDialog progressDialog = ModernFormProgressDialog();
    var stream = BehaviorSubject<double>.seeded(0.0);
    var streamText =
        BehaviorSubject<String>.seeded('Fazendo download do arquivo...');
    progressDialog.showProgressDialog(
      streamValue: stream,
      streamText: streamText,
      progressColor: Colors.white,
      barrierColor: Color(0x88222222),
    );

    Uint8List? bytes = await downloadFromYoutube(
      url,
      (totalByteCount, bytesTransferred) {
        double percent = 0;
        percent = bytesTransferred / totalByteCount;

        stream.add(percent);
        streamText.add("${(percent * 100).toStringAsFixed(2)}% concluĂ­do...");
      },
      true,
    );
    stream.close();
    streamText.close();
    progressDialog.dismissProgressDialog();

    return bytes;
  } else {
    return ModernFormDownloadHelper.downloadWithProgress(url);
  }
}