Skip to content

Commit

Permalink
fix a Slider theme update bug (#120432)
Browse files Browse the repository at this point in the history
* fix a Slider theme update bug

* Code review feedback
  • Loading branch information
xu-baolin authored Feb 13, 2023
1 parent 53fe8a3 commit b0c24e8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
return;
}
_sliderTheme = value;
markNeedsPaint();
_updateLabelPainter();
}

double get textScaleFactor => _textScaleFactor;
Expand Down
45 changes: 45 additions & 0 deletions packages/flutter/test/material/slider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,51 @@ void main() {
);
});

testWidgets('SliderTheme change should trigger re-layout', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/118955
double sliderValue = 0.0;
Widget buildFrame(ThemeMode themeMode) {
return MaterialApp(
themeMode: themeMode,
theme: ThemeData(brightness: Brightness.light, useMaterial3: true),
darkTheme: ThemeData(brightness: Brightness.dark, useMaterial3: true),
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: SizedBox(
height: 10.0,
width: 10.0,
child: Slider(
value: sliderValue,
label: 'label',
onChanged: (double value) => sliderValue = value,
),
),
),
),
),
);
}

await tester.pumpWidget(buildFrame(ThemeMode.light));

// _RenderSlider is the last render object in the tree.
final RenderObject renderObject = tester.allRenderObjects.last;
expect(renderObject.debugNeedsLayout, false);

await tester.pumpWidget(buildFrame(ThemeMode.dark));
await tester.pump(
const Duration(milliseconds: 100), // to let the theme animate
EnginePhase.build,
);

expect(renderObject.debugNeedsLayout, true);

// Pump the rest of the frames to complete the test.
await tester.pumpAndSettle();
});

testWidgets('Slider can be painted in a narrower constraint', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
Expand Down

0 comments on commit b0c24e8

Please sign in to comment.