Leave a rating/review
DownloadView has a Boolean State property isDownloadActive. It passes a binding to this property to FileDetails, where its value controls the display of a ProgressView — a spinning activity indicator — next to the filename.
Your challenge is to show this progress view when the download starts and hide it when the download finishes.
Be sure to also hide the progress view if the download task throws an error.
You only need to add a few lines of code to the downloadSingleAction definition. In the Task closure, you’ll need a do-catch block to handle the error case.
Good luck!
Welcome back! Hopefully you had success with this task. Here’s how I did it.
Start spinner
In the downloadSingleAction definition, I added this code before Task:
isDownloadActive = true
This gets the spinner spinning.
In the Task closure, I replaced the single line of code with this:
do {
fileData = try await model.download(file: file)
} catch { }
isDownloadActive = false
Whether or not there’s a download error, I set isDownloadActive to false.
Build and run, select a jpeg file and tap Silver.
And there was your activity indicator! Well done! You’ve implemented the Silver plan. In the next episode, you’ll start work on the Gold plan.