percentFromProgress function
Turns a background_downloader progress value into a percentage, or null when it is a STATE SENTINEL rather than progress.
The package signals state through negative values on the progress channel: -1 failed, -2 canceled, -3 notFound, -4 waiting to retry, -5 paused. Clamping those to 0 made the bar snap to 0% at every 9-minute WorkManager slice.
Implementation
@visibleForTesting
int? percentFromProgress(double progress) =>
progress < 0 ? null : (progress * 100).round().clamp(0, 100);