Skip to content

Commit 0b72e92

Browse files
authored
[material_ui] Mirror the GappedSliderTrackShape secondary track correctly in RTL (flutter#13226)
In RTL, `GappedSliderTrackShape` drew the secondary track from `secondaryOffset.dx - trackGap` to `thumbCenter.dx`. That filled the gap next to the thumb, which the main track segments and the LTR secondary track keep empty. The corner radii were also copied from the LTR case instead of being mirrored, so the far end had the small inside corners and the end by the thumb was fully rounded. This PR draws the RTL secondary track from `secondaryOffset.dx` to `thumbCenter.dx - trackGap`, with the fully rounded corners on the far end and the small inside corners next to the thumb. That is the mirror image of the LTR case. The existing visibility check just above already used `thumbCenter.dx - trackGap`, so it matches the new geometry. Before and after, LTR on top and RTL below, with `Slider(year2023: false, secondaryTrackValue: ...)` and `trackHeight: 24`: <details open> <summary>Screenshots demonstration</summary> | State | Direction | Screenshot | | :---: | :---: | :---: | | **Before** | <kbd>LTR ➔</kbd><br><br><br><kbd>⬅ RTL</kbd> | <img width="1200" height="320" alt="2_gapped_BEFORE" src="https://github.com/user-attachments/assets/dfc9eb92-9b0c-4fd6-a087-253e7a0b586d" /> | | **After** | <kbd>LTR ➔</kbd><br><br><br><kbd>⬅ RTL</kbd> | <img width="1200" height="320" alt="2_gapped_AFTER" src="https://github.com/user-attachments/assets/99599f28-dd24-41b6-80f3-cf889bc2fa74" /> | </details> I extended the existing `Default Slider when year2023 is false` test. It now also asserts the exact LTR secondary track, and has a new RTL block with the mirrored inactive, active and secondary tracks, including corner radii. The RTL block fails without the fix. Fixes flutter#194279 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 2def459 commit 0b72e92

3 files changed

Lines changed: 82 additions & 8 deletions

File tree

‎packages/material_ui/lib/src/slider_parts.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,14 @@ class GappedSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape
12001200
} else {
12011201
context.canvas.drawRRect(
12021202
RRect.fromLTRBAndCorners(
1203-
secondaryOffset.dx - trackGap,
1203+
secondaryOffset.dx,
12041204
trackRect.top,
1205-
thumbCenter.dx,
1205+
thumbCenter.dx - trackGap,
12061206
trackRect.bottom,
1207-
topLeft: trackInsideCornerRadius,
1208-
bottomLeft: trackInsideCornerRadius,
1209-
topRight: trackCornerRadius,
1210-
bottomRight: trackCornerRadius,
1207+
topLeft: trackCornerRadius,
1208+
bottomLeft: trackCornerRadius,
1209+
topRight: trackInsideCornerRadius,
1210+
bottomRight: trackInsideCornerRadius,
12111211
),
12121212
secondaryTrackPaint,
12131213
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes `GappedSliderTrackShape` painting the secondary track with the wrong position and corners in right-to-left layouts.
3+
version: patch

‎packages/material_ui/test/slider_test.dart‎

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5400,15 +5400,19 @@ void main() {
54005400
final Color disabledThumbColor = colorScheme.onSurface.withOpacity(0.38);
54015401
final Color valueIndicatorColor = colorScheme.inverseSurface;
54025402
var value = 0.45;
5403-
Widget buildApp({int? divisions, bool enabled = true}) {
5403+
Widget buildApp({
5404+
int? divisions,
5405+
bool enabled = true,
5406+
TextDirection textDirection = TextDirection.ltr,
5407+
}) {
54045408
final ValueChanged<double>? onChanged = !enabled
54055409
? null
54065410
: (double d) {
54075411
value = d;
54085412
};
54095413
return MaterialApp(
54105414
home: Directionality(
5411-
textDirection: TextDirection.ltr,
5415+
textDirection: textDirection,
54125416
child: Material(
54135417
child: Center(
54145418
child: Theme(
@@ -5465,9 +5469,76 @@ void main() {
54655469
bottomLeft: trackInnerCornerRadius,
54665470
),
54675471
color: inactiveTrackColor,
5472+
)
5473+
// Secondary track.
5474+
..rrect(
5475+
rrect: RRect.fromLTRBAndCorners(
5476+
368.4,
5477+
292.0,
5478+
588.0,
5479+
308.0,
5480+
topLeft: trackInnerCornerRadius,
5481+
topRight: trackOuterCornerRadius,
5482+
bottomRight: trackOuterCornerRadius,
5483+
bottomLeft: trackInnerCornerRadius,
5484+
),
5485+
color: secondaryActiveTrackColor,
54685486
),
54695487
);
54705488

5489+
// Test default track shape in RTL. It is the mirror image of the one in LTR,
5490+
// and the secondary track stops a track gap before the thumb.
5491+
// Regression test for https://github.com/flutter/flutter/issues/194279
5492+
await tester.pumpWidget(buildApp(textDirection: TextDirection.rtl));
5493+
expect(
5494+
material,
5495+
paints
5496+
// Inactive track.
5497+
..rrect(
5498+
rrect: RRect.fromLTRBAndCorners(
5499+
24.0,
5500+
292.0,
5501+
431.6,
5502+
308.0,
5503+
topLeft: trackOuterCornerRadius,
5504+
topRight: trackInnerCornerRadius,
5505+
bottomRight: trackInnerCornerRadius,
5506+
bottomLeft: trackOuterCornerRadius,
5507+
),
5508+
color: inactiveTrackColor,
5509+
)
5510+
// Active track.
5511+
..rrect(
5512+
rrect: RRect.fromLTRBAndCorners(
5513+
443.6,
5514+
292.0,
5515+
776.0,
5516+
308.0,
5517+
topLeft: trackInnerCornerRadius,
5518+
topRight: trackOuterCornerRadius,
5519+
bottomRight: trackOuterCornerRadius,
5520+
bottomLeft: trackInnerCornerRadius,
5521+
),
5522+
color: activeTrackColor,
5523+
)
5524+
// Secondary track.
5525+
..rrect(
5526+
rrect: RRect.fromLTRBAndCorners(
5527+
212.0,
5528+
292.0,
5529+
431.6,
5530+
308.0,
5531+
topLeft: trackOuterCornerRadius,
5532+
topRight: trackInnerCornerRadius,
5533+
bottomRight: trackInnerCornerRadius,
5534+
bottomLeft: trackOuterCornerRadius,
5535+
),
5536+
color: secondaryActiveTrackColor,
5537+
),
5538+
);
5539+
5540+
await tester.pumpWidget(buildApp());
5541+
54715542
// Test default colors for enabled slider.
54725543
expect(
54735544
material,

0 commit comments

Comments
 (0)