Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Slider] Refactor test "Value indicator appears when it should"#183143

Open
dkwingsmt wants to merge 2 commits intoflutter:masterfrom
dkwingsmt:refactor-slider-test
Open

[Slider] Refactor test "Value indicator appears when it should"#183143
dkwingsmt wants to merge 2 commits intoflutter:masterfrom
dkwingsmt:refactor-slider-test

Conversation

@dkwingsmt
Copy link
Contributor

This PR refactors this slider test so that

  • The test is split into multiple tests in a single group for better readability.
  • A single expectValueIndicator tests both the dragged state and the released state, for better readability.
  • The widget state is reset at the end of expectValueIndicator to avoid state leak...
  • ... which revealed a test case that has been written incorrectly.
  • ShowValueIndicator.alwaysVisible's doc is corrected to reflect its actual behavior.

This PR is split from, and is a prerequisite of, #182991.

Pre-launch Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@dkwingsmt dkwingsmt requested a review from navaronbracke March 2, 2026 23:32
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Mar 2, 2026
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 refactors a large test for slider value indicators into smaller, more readable tests grouped by behavior. It introduces a new test helper that checks both dragged and released states and resets the widget state to prevent leaks between test runs. This refactoring also led to the correction of a test case and related documentation for ShowValueIndicator.alwaysVisible. The changes significantly improve the test suite's readability and reliability. I have one minor suggestion to further improve code clarity in one of the new tests.

Note: Security Review is unavailable for this PR.

await expectValueIndicator(isVisible: true, theme: theme, dragged: false);
await expectValueIndicator(isVisible: true, theme: theme, enabled: false, dragged: false);
testWidgets('showValueIndicator set to onlyForDiscrete', (WidgetTester tester) async {
final sliderTheme = baseSliderTheme;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The sliderTheme local variable is redundant here as it's just an alias for baseSliderTheme. For improved readability and consistency with the other tests in this group that create modified themes, consider removing this variable and using baseSliderTheme directly in the expectValueIndicator calls.

References
  1. Code should be optimized for readability, as it is read more often than it is written. Removing this redundant variable makes the code slightly clearer. (link)

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant