Mr.Droid
Mr.Droid

Reputation: 303

Compose - How to make ProgressBar determinate in code?

In some cases I need to display indeterminate progress bar and then convert it to determinate in a specific case. How can this be done in compose?

Example

When downloading a file. I need to display an indeterminate progress bar as a start and then convert it to a determinate progress bar

In Views this can be done with the setIndeterminate() . function

Upvotes: 1

Views: 680

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363795

When you use the LinearProgressIndicator or CircularProgressIndicator without the progress parameter, it is indeterminate .

You can use something like:

var indeterminate by remember { mutableStateOf(true) }

if (indeterminate) {
    LinearProgressIndicator()
} else {
    LinearProgressIndicator(progress = animatedProgress)
}

enter image description here

Upvotes: 2

Related Questions