Skip to content

Fix LinearProgressIndicator track painting.#173108

Merged
auto-submit[bot] merged 9 commits intoflutter:masterfrom
ksokolovskyi:fix-linear-progress-indicator-track-painting
Sep 3, 2025
Merged

Fix LinearProgressIndicator track painting.#173108
auto-submit[bot] merged 9 commits intoflutter:masterfrom
ksokolovskyi:fix-linear-progress-indicator-track-painting

Conversation

@ksokolovskyi
Copy link
Contributor

@ksokolovskyi ksokolovskyi commented Aug 1, 2025

Fixes #164538
Fixes #173096
Fixes #173153

Description

  • Adds support for trackGap in indeterminate LinearProgressIndicator
  • Fixes track painting outside of LinearProgressIndicator bounds when trackGap is greater than zero
  • Fixes LinearProgressIndicator track gap painting when value is 0
  • Adds golden tests

androidx.compose.material3 and material-components-android implementations were used as a reference.

Before After
Determinate (regular)
before after
Determinate (trackGap: 20)
before after
Indeterminate (regular)
before after
Indeterminate (trackGap: 20)
before after

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 1, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where the LinearProgressIndicator track was painting outside of its bounds when a trackGap was specified. The fix involves clamping the track's rectangle coordinates and adding a check for track width before drawing. A regression golden test has also been added.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #173108 at sha 9ec08fa

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Aug 1, 2025
@ksokolovskyi ksokolovskyi marked this pull request as draft August 2, 2025 20:30
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dkwingsmt dkwingsmt requested a review from victorsanni August 6, 2025 18:10
@ksokolovskyi ksokolovskyi marked this pull request as ready for review August 11, 2025 13:40
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #173108 at sha 79465a7

@victorsanni victorsanni requested a review from QuncCccccc August 11, 2025 19:29
Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't finished my review but thank you so much for your contribution. Overall it looks good! Will take another look! The golden tests look great!

@ksokolovskyi
Copy link
Contributor Author

Hi @QuncCccccc, thanks a lot for your review and suggestions! I added a number of comments to help understand the code. Could you please take a look again when you have time?

@ksokolovskyi ksokolovskyi changed the title Fix LinearProgressIndicator track painting outside of bounds. Fix LinearProgressIndicator track painting. Aug 22, 2025
@ksokolovskyi
Copy link
Contributor Author

@QuncCccccc, I noticed that the Android material-components implementation of the progress indicator handles the effective trackGap differently. In that version, the trackGap gradually increases until progress reaches 1%, after which it remains at its full length (Source 1, Source 2).

Below is the comparison of the two approaches with a trackGap: 20. The top one is from the Compose (the one which is used in this PR), and the bottom one is from the Android material-components library.

track_gaps.mov

The code for the new approach:

double getEffectiveTrackGapFraction(double currentValue, double trackGapFraction) {
  // If the progress is less than 1%, the gap will be proportional to the
  // progress. So that, it draws a full track at 0%.
  const double kGapRampDownThreshold = 0.01;

  return trackGapFraction *
      clampDouble(currentValue, 0, kGapRampDownThreshold) /
      kGapRampDownThreshold;
}

Given this difference in the effective trackGap calculation, should we align with the Android implementation, or use a Compose one?

@QuncCccccc
Copy link
Contributor

QuncCccccc commented Aug 25, 2025

I think both are fine. We can use the current algorithm as is because I think usually the gap is small and we can barely detect the difference during animation.

Update: I just talked with @TahaTesser who implemented the updated LinearProgressIndicator. Since overall the Android material-components repo are more reliable and usually have faster updates from newer Material specs, keeping the original calculation (material-components) would be a better option.

Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank for your fix:) Add this comment here again in case it's missed:) #173108 (comment)

@ksokolovskyi ksokolovskyi requested review from a team as code owners August 26, 2025 12:34
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems platform-android Android applications specifically platform-ios iOS applications specifically labels Aug 26, 2025
@ksokolovskyi
Copy link
Contributor Author

@QuncCccccc, sorry for the spam, I messed up a bit with git.

I updated the effective trackGap calculation to be exactly as in the Android material-components library. This will probably update the goldens again. Could you please give this PR another look?

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #173108 at sha 639c579

@QuncCccccc QuncCccccc self-requested a review August 26, 2025 16:56
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #173108 at sha 777e414

Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 3, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Sep 3, 2025
@ksokolovskyi
Copy link
Contributor Author

@QuncCccccc thanks a lot for your review and suggestions!

Merged via the queue into flutter:master with commit 52d5c5d Sep 3, 2025
77 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 3, 2025
@ksokolovskyi
Copy link
Contributor Author

@QuncCccccc I don't see Google Testing in checks, and not sure why it wasn't run after the master branch merge. Today morning, Google Testing was failing in this PR, so in case there are any issues with the tree, we need to revert this PR.

@QuncCccccc
Copy link
Contributor

Oh thank for letting me know! For this kind of change, we probably should only submit it after Google testing has passed next time.

not sure why it wasn't run after the master branch merge.

Yeah, the google testing sometimes just don't start testing. Might need to try to re-trigger it by rebasing with master.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

2 participants