downloadWidget method

Widget downloadWidget({
  1. DownloadState? downloadState,
  2. required double percentageDownloaded,
  3. required VoidCallback openOptionQuality,
  4. required VoidCallback retryDownload,
  5. required VoidCallback cancelDownload,
})

Implementation

Widget downloadWidget(
    {DownloadState? downloadState,
    required double percentageDownloaded,
    required VoidCallback openOptionQuality,
    required VoidCallback retryDownload,
    required VoidCallback cancelDownload}) {
  switch (downloadState) {
    case DownloadState.downloadQueued:
      return Stack(alignment: Alignment.center, children: [
        circleProgressBar(0, true),
        buttonClick(
            const Icon(
              Icons.stop,
              color: Colors.transparent,
            ),
            24, () {
          cancelDownload.call();
        })
      ]);
    case DownloadState.downloadStarted:
      return Stack(alignment: Alignment.center, children: [
        circleProgressBar(percentageDownloaded, false),
        buttonClick(
            const Icon(
              Icons.stop,
              color: Colors.white,
            ),
            24, () {
          cancelDownload.call();
        })
      ]);
    case DownloadState.downloadPaused:
      return Stack(
        alignment: Alignment.center,
        children: [
          circleProgressBar(percentageDownloaded, false),
          buttonClick(
              const Icon(
                Icons.arrow_downward,
                color: Colors.white,
              ),
              24,
              () {})
        ],
      );
    case DownloadState.downloadResumed:
      return Stack(
        alignment: Alignment.center,
        children: [
          circleProgressBar(percentageDownloaded, false),
          buttonClick(
              const Icon(
                Icons.stop,
                color: Colors.white,
              ),
              24, () {
            cancelDownload.call();
          })
        ],
      );
    case DownloadState.downloadCanceled:
      return Stack(
        alignment: Alignment.center,
        children: [
          buttonClick(
              const Icon(
                Icons.arrow_downward,
                color: Colors.white,
              ),
              24, () {
            openOptionQuality.call();
          })
        ],
      );
    case DownloadState.downloadFailed:
      return Stack(
        alignment: Alignment.center,
        children: [
          buttonClick(
              const Icon(
                Icons.refresh,
                color: Colors.white,
              ),
              24, () {
            retryDownload.call();
          })
        ],
      );
    case DownloadState.downloadCompleted:
      return Stack(
        alignment: Alignment.center,
        children: [
          buttonClick(
              const Icon(
                Icons.assignment_turned_in_outlined,
                color: Colors.white,
              ),
              24,
              () {})
        ],
      );
    case DownloadState.downloadNotYet:
      return Stack(
        alignment: Alignment.center,
        children: [
          buttonClick(
              const Icon(
                Icons.arrow_downward,
                color: Colors.white,
              ),
              24, () {
            openOptionQuality.call();
          })
        ],
      );
    case null:
      {
        return const SizedBox();
      }
  }
}