Unverified Commit fb664702 authored by nohli's avatar nohli Committed by GitHub

Add slider adaptive cupertino thumb color (#81647)

parent 016ad85d
......@@ -153,6 +153,7 @@ class Slider extends StatefulWidget {
this.label,
this.activeColor,
this.inactiveColor,
this.thumbColor,
this.mouseCursor,
this.semanticFormatterCallback,
this.focusNode,
......@@ -190,6 +191,7 @@ class Slider extends StatefulWidget {
this.mouseCursor,
this.activeColor,
this.inactiveColor,
this.thumbColor,
this.semanticFormatterCallback,
this.focusNode,
this.autofocus = false,
......@@ -382,6 +384,14 @@ class Slider extends StatefulWidget {
/// Ignored if this slider is created with [Slider.adaptive].
final Color? inactiveColor;
/// The color of the thumb.
///
/// If this color is null:
/// * [Slider] will use [activeColor].
/// * [CupertinoSlider] will have a white thumb
/// (like the native default iOS slider).
final Color? thumbColor;
/// The cursor for a mouse pointer when it enters or is hovering over the
/// widget.
///
......@@ -679,7 +689,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
inactiveTickMarkColor: widget.activeColor ?? sliderTheme.inactiveTickMarkColor ?? theme.colorScheme.primary.withOpacity(0.54),
disabledActiveTickMarkColor: sliderTheme.disabledActiveTickMarkColor ?? theme.colorScheme.onPrimary.withOpacity(0.12),
disabledInactiveTickMarkColor: sliderTheme.disabledInactiveTickMarkColor ?? theme.colorScheme.onSurface.withOpacity(0.12),
thumbColor: widget.activeColor ?? sliderTheme.thumbColor ?? theme.colorScheme.primary,
thumbColor: widget.thumbColor ?? widget.activeColor ?? sliderTheme.thumbColor ?? theme.colorScheme.primary,
disabledThumbColor: sliderTheme.disabledThumbColor ?? Color.alphaBlend(theme.colorScheme.onSurface.withOpacity(.38), theme.colorScheme.surface),
overlayColor: widget.activeColor?.withOpacity(0.12) ?? sliderTheme.overlayColor ?? theme.colorScheme.primary.withOpacity(0.12),
valueIndicatorColor: valueIndicatorColor,
......@@ -757,6 +767,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
max: widget.max,
divisions: widget.divisions,
activeColor: widget.activeColor,
thumbColor: widget.thumbColor ?? CupertinoColors.white,
),
);
}
......
......@@ -2513,4 +2513,105 @@ void main() {
// 24.0 is the default margin, (800.0 - 24.0 - 24.0) is the slider's width.
expect(nearEqual(activeTrackRRect.right, (800.0 - 24.0 - 24.0) * (5 / 15) + 24.0, 0.01), true);
});
testWidgets('Slider paints thumbColor', (WidgetTester tester) async {
const Color color = Color(0xffffc107);
final Widget sliderAdaptive = MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material(
child: Slider(
value: 0,
onChanged: (double newValue) {},
thumbColor: color,
),
),
);
await tester.pumpWidget(sliderAdaptive);
await tester.pumpAndSettle();
final MaterialInkController material =
Material.of(tester.element(find.byType(Slider)))!;
expect(material, paints..circle(color: color));
});
testWidgets('Slider.adaptive paints thumbColor on Android',
(WidgetTester tester) async {
const Color color = Color(0xffffc107);
final Widget sliderAdaptive = MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Material(
child: Slider.adaptive(
value: 0,
onChanged: (double newValue) {},
thumbColor: color,
),
),
);
await tester.pumpWidget(sliderAdaptive);
await tester.pumpAndSettle();
final MaterialInkController material =
Material.of(tester.element(find.byType(Slider)))!;
expect(material, paints..circle(color: color));
});
testWidgets('If thumbColor is null, it defaults to CupertinoColors.white',
(WidgetTester tester) async {
final Widget sliderAdaptive = MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material(
child: Slider.adaptive(
value: 0,
onChanged: (double newValue) {},
),
),
);
await tester.pumpWidget(sliderAdaptive);
await tester.pumpAndSettle();
final MaterialInkController material =
Material.of(tester.element(find.byType(CupertinoSlider)))!;
expect(
material,
paints
..rrect()
..rrect()
..rrect()
..rrect()
..rrect()
..rrect(color: CupertinoColors.white),
);
});
testWidgets('Slider.adaptive passes thumbColor to CupertinoSlider',
(WidgetTester tester) async {
const Color color = Color(0xffffc107);
final Widget sliderAdaptive = MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material(
child: Slider.adaptive(
value: 0,
onChanged: (double newValue) {},
thumbColor: color,
),
),
);
await tester.pumpWidget(sliderAdaptive);
await tester.pumpAndSettle();
final MaterialInkController material =
Material.of(tester.element(find.byType(CupertinoSlider)))!;
expect(
material,
paints..rrect()..rrect()..rrect()..rrect()..rrect()..rrect(color: color),
);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment