Unverified Commit 5434dd59 authored by Per Classon's avatar Per Classon Committed by GitHub

[Material] Add splash radius property to selection controls (#69197)

parent 8cbc8492
...@@ -66,6 +66,7 @@ class Checkbox extends StatefulWidget { ...@@ -66,6 +66,7 @@ class Checkbox extends StatefulWidget {
this.checkColor, this.checkColor,
this.focusColor, this.focusColor,
this.hoverColor, this.hoverColor,
this.splashRadius,
this.materialTapTargetSize, this.materialTapTargetSize,
this.visualDensity, this.visualDensity,
this.focusNode, this.focusNode,
...@@ -173,6 +174,11 @@ class Checkbox extends StatefulWidget { ...@@ -173,6 +174,11 @@ class Checkbox extends StatefulWidget {
/// The color for the checkbox's [Material] when a pointer is hovering over it. /// The color for the checkbox's [Material] when a pointer is hovering over it.
final Color? hoverColor; final Color? hoverColor;
/// The splash radius of the circular [Material] ink response.
///
/// If null, then [kRadialReactionRadius] is used.
final double? splashRadius;
/// {@macro flutter.widgets.Focus.focusNode} /// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode; final FocusNode? focusNode;
...@@ -237,10 +243,10 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin { ...@@ -237,10 +243,10 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
Size size; Size size;
switch (widget.materialTapTargetSize ?? themeData!.materialTapTargetSize) { switch (widget.materialTapTargetSize ?? themeData!.materialTapTargetSize) {
case MaterialTapTargetSize.padded: case MaterialTapTargetSize.padded:
size = const Size(2 * kRadialReactionRadius + 8.0, 2 * kRadialReactionRadius + 8.0); size = const Size(kMinInteractiveDimension, kMinInteractiveDimension);
break; break;
case MaterialTapTargetSize.shrinkWrap: case MaterialTapTargetSize.shrinkWrap:
size = const Size(2 * kRadialReactionRadius, 2 * kRadialReactionRadius); size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0);
break; break;
} }
size += (widget.visualDensity ?? themeData!.visualDensity).baseSizeAdjustment; size += (widget.visualDensity ?? themeData!.visualDensity).baseSizeAdjustment;
...@@ -273,6 +279,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin { ...@@ -273,6 +279,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
inactiveColor: enabled ? themeData!.unselectedWidgetColor : themeData!.disabledColor, inactiveColor: enabled ? themeData!.unselectedWidgetColor : themeData!.disabledColor,
focusColor: widget.focusColor ?? themeData.focusColor, focusColor: widget.focusColor ?? themeData.focusColor,
hoverColor: widget.hoverColor ?? themeData.hoverColor, hoverColor: widget.hoverColor ?? themeData.hoverColor,
splashRadius: widget.splashRadius ?? kRadialReactionRadius,
onChanged: widget.onChanged, onChanged: widget.onChanged,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
vsync: this, vsync: this,
...@@ -295,6 +302,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -295,6 +302,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
required this.inactiveColor, required this.inactiveColor,
required this.focusColor, required this.focusColor,
required this.hoverColor, required this.hoverColor,
required this.splashRadius,
required this.onChanged, required this.onChanged,
required this.vsync, required this.vsync,
required this.additionalConstraints, required this.additionalConstraints,
...@@ -316,6 +324,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -316,6 +324,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
final Color inactiveColor; final Color inactiveColor;
final Color focusColor; final Color focusColor;
final Color hoverColor; final Color hoverColor;
final double splashRadius;
final ValueChanged<bool?>? onChanged; final ValueChanged<bool?>? onChanged;
final TickerProvider vsync; final TickerProvider vsync;
final BoxConstraints additionalConstraints; final BoxConstraints additionalConstraints;
...@@ -329,6 +338,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -329,6 +338,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
focusColor: focusColor, focusColor: focusColor,
hoverColor: hoverColor, hoverColor: hoverColor,
splashRadius: splashRadius,
onChanged: onChanged, onChanged: onChanged,
vsync: vsync, vsync: vsync,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
...@@ -348,6 +358,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -348,6 +358,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
..inactiveColor = inactiveColor ..inactiveColor = inactiveColor
..focusColor = focusColor ..focusColor = focusColor
..hoverColor = hoverColor ..hoverColor = hoverColor
..splashRadius = splashRadius
..onChanged = onChanged ..onChanged = onChanged
..additionalConstraints = additionalConstraints ..additionalConstraints = additionalConstraints
..vsync = vsync ..vsync = vsync
...@@ -369,6 +380,7 @@ class _RenderCheckbox extends RenderToggleable { ...@@ -369,6 +380,7 @@ class _RenderCheckbox extends RenderToggleable {
required Color inactiveColor, required Color inactiveColor,
Color? focusColor, Color? focusColor,
Color? hoverColor, Color? hoverColor,
required double splashRadius,
required BoxConstraints additionalConstraints, required BoxConstraints additionalConstraints,
ValueChanged<bool?>? onChanged, ValueChanged<bool?>? onChanged,
required bool hasFocus, required bool hasFocus,
...@@ -382,6 +394,7 @@ class _RenderCheckbox extends RenderToggleable { ...@@ -382,6 +394,7 @@ class _RenderCheckbox extends RenderToggleable {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
focusColor: focusColor, focusColor: focusColor,
hoverColor: hoverColor, hoverColor: hoverColor,
splashRadius: splashRadius,
onChanged: onChanged, onChanged: onChanged,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
vsync: vsync, vsync: vsync,
......
...@@ -30,7 +30,7 @@ const double kTextTabBarHeight = kMinInteractiveDimension; ...@@ -30,7 +30,7 @@ const double kTextTabBarHeight = kMinInteractiveDimension;
/// The amount of time theme change animations should last. /// The amount of time theme change animations should last.
const Duration kThemeChangeDuration = Duration(milliseconds: 200); const Duration kThemeChangeDuration = Duration(milliseconds: 200);
/// The radius of a circular material ink response in logical pixels. /// The default radius of a circular material ink response in logical pixels.
const double kRadialReactionRadius = 20.0; const double kRadialReactionRadius = 20.0;
/// The amount of time a circular material ink response should take to expand to its full size. /// The amount of time a circular material ink response should take to expand to its full size.
......
...@@ -114,6 +114,7 @@ class Radio<T> extends StatefulWidget { ...@@ -114,6 +114,7 @@ class Radio<T> extends StatefulWidget {
this.activeColor, this.activeColor,
this.focusColor, this.focusColor,
this.hoverColor, this.hoverColor,
this.splashRadius,
this.materialTapTargetSize, this.materialTapTargetSize,
this.visualDensity, this.visualDensity,
this.focusNode, this.focusNode,
...@@ -266,6 +267,11 @@ class Radio<T> extends StatefulWidget { ...@@ -266,6 +267,11 @@ class Radio<T> extends StatefulWidget {
/// The color for the radio's [Material] when a pointer is hovering over it. /// The color for the radio's [Material] when a pointer is hovering over it.
final Color? hoverColor; final Color? hoverColor;
/// The splash radius of the circular [Material] ink response.
///
/// If null, then [kRadialReactionRadius] is used.
final double? splashRadius;
/// {@macro flutter.widgets.Focus.focusNode} /// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode; final FocusNode? focusNode;
...@@ -333,10 +339,10 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin { ...@@ -333,10 +339,10 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin {
Size size; Size size;
switch (widget.materialTapTargetSize ?? themeData.materialTapTargetSize) { switch (widget.materialTapTargetSize ?? themeData.materialTapTargetSize) {
case MaterialTapTargetSize.padded: case MaterialTapTargetSize.padded:
size = const Size(2 * kRadialReactionRadius + 8.0, 2 * kRadialReactionRadius + 8.0); size = const Size(kMinInteractiveDimension, kMinInteractiveDimension);
break; break;
case MaterialTapTargetSize.shrinkWrap: case MaterialTapTargetSize.shrinkWrap:
size = const Size(2 * kRadialReactionRadius, 2 * kRadialReactionRadius); size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0);
break; break;
} }
size += (widget.visualDensity ?? themeData.visualDensity).baseSizeAdjustment; size += (widget.visualDensity ?? themeData.visualDensity).baseSizeAdjustment;
...@@ -368,6 +374,7 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin { ...@@ -368,6 +374,7 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin {
inactiveColor: _getInactiveColor(themeData), inactiveColor: _getInactiveColor(themeData),
focusColor: widget.focusColor ?? themeData.focusColor, focusColor: widget.focusColor ?? themeData.focusColor,
hoverColor: widget.hoverColor ?? themeData.hoverColor, hoverColor: widget.hoverColor ?? themeData.hoverColor,
splashRadius: widget.splashRadius ?? kRadialReactionRadius,
onChanged: enabled ? _handleChanged : null, onChanged: enabled ? _handleChanged : null,
toggleable: widget.toggleable, toggleable: widget.toggleable,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
...@@ -395,6 +402,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -395,6 +402,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget {
required this.vsync, required this.vsync,
required this.hasFocus, required this.hasFocus,
required this.hovering, required this.hovering,
required this.splashRadius,
}) : assert(selected != null), }) : assert(selected != null),
assert(activeColor != null), assert(activeColor != null),
assert(inactiveColor != null), assert(inactiveColor != null),
...@@ -409,6 +417,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -409,6 +417,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget {
final Color activeColor; final Color activeColor;
final Color focusColor; final Color focusColor;
final Color hoverColor; final Color hoverColor;
final double splashRadius;
final ValueChanged<bool?>? onChanged; final ValueChanged<bool?>? onChanged;
final bool toggleable; final bool toggleable;
final TickerProvider vsync; final TickerProvider vsync;
...@@ -421,6 +430,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -421,6 +430,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
focusColor: focusColor, focusColor: focusColor,
hoverColor: hoverColor, hoverColor: hoverColor,
splashRadius: splashRadius,
onChanged: onChanged, onChanged: onChanged,
tristate: toggleable, tristate: toggleable,
vsync: vsync, vsync: vsync,
...@@ -437,6 +447,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -437,6 +447,7 @@ class _RadioRenderObjectWidget extends LeafRenderObjectWidget {
..inactiveColor = inactiveColor ..inactiveColor = inactiveColor
..focusColor = focusColor ..focusColor = focusColor
..hoverColor = hoverColor ..hoverColor = hoverColor
..splashRadius = splashRadius
..onChanged = onChanged ..onChanged = onChanged
..tristate = toggleable ..tristate = toggleable
..additionalConstraints = additionalConstraints ..additionalConstraints = additionalConstraints
...@@ -453,6 +464,7 @@ class _RenderRadio extends RenderToggleable { ...@@ -453,6 +464,7 @@ class _RenderRadio extends RenderToggleable {
required Color inactiveColor, required Color inactiveColor,
required Color focusColor, required Color focusColor,
required Color hoverColor, required Color hoverColor,
required double splashRadius,
required ValueChanged<bool?>? onChanged, required ValueChanged<bool?>? onChanged,
required bool tristate, required bool tristate,
required BoxConstraints additionalConstraints, required BoxConstraints additionalConstraints,
...@@ -465,6 +477,7 @@ class _RenderRadio extends RenderToggleable { ...@@ -465,6 +477,7 @@ class _RenderRadio extends RenderToggleable {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
focusColor: focusColor, focusColor: focusColor,
hoverColor: hoverColor, hoverColor: hoverColor,
splashRadius: splashRadius,
onChanged: onChanged, onChanged: onChanged,
tristate: tristate, tristate: tristate,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
......
...@@ -21,9 +21,10 @@ const double _kTrackHeight = 14.0; ...@@ -21,9 +21,10 @@ const double _kTrackHeight = 14.0;
const double _kTrackWidth = 33.0; const double _kTrackWidth = 33.0;
const double _kTrackRadius = _kTrackHeight / 2.0; const double _kTrackRadius = _kTrackHeight / 2.0;
const double _kThumbRadius = 10.0; const double _kThumbRadius = 10.0;
const double _kSwitchWidth = _kTrackWidth - 2 * _kTrackRadius + 2 * kRadialReactionRadius; const double _kSwitchMinSize = kMinInteractiveDimension - 8.0;
const double _kSwitchHeight = 2 * kRadialReactionRadius + 8.0; const double _kSwitchWidth = _kTrackWidth - 2 * _kTrackRadius + _kSwitchMinSize;
const double _kSwitchHeightCollapsed = 2 * kRadialReactionRadius; const double _kSwitchHeight = _kSwitchMinSize + 8.0;
const double _kSwitchHeightCollapsed = _kSwitchMinSize;
enum _SwitchType { material, adaptive } enum _SwitchType { material, adaptive }
...@@ -80,6 +81,7 @@ class Switch extends StatefulWidget { ...@@ -80,6 +81,7 @@ class Switch extends StatefulWidget {
this.mouseCursor, this.mouseCursor,
this.focusColor, this.focusColor,
this.hoverColor, this.hoverColor,
this.splashRadius,
this.focusNode, this.focusNode,
this.autofocus = false, this.autofocus = false,
}) : _switchType = _SwitchType.material, }) : _switchType = _SwitchType.material,
...@@ -114,6 +116,7 @@ class Switch extends StatefulWidget { ...@@ -114,6 +116,7 @@ class Switch extends StatefulWidget {
this.mouseCursor, this.mouseCursor,
this.focusColor, this.focusColor,
this.hoverColor, this.hoverColor,
this.splashRadius,
this.focusNode, this.focusNode,
this.autofocus = false, this.autofocus = false,
}) : assert(autofocus != null), }) : assert(autofocus != null),
...@@ -229,6 +232,11 @@ class Switch extends StatefulWidget { ...@@ -229,6 +232,11 @@ class Switch extends StatefulWidget {
/// The color for the button's [Material] when a pointer is hovering over it. /// The color for the button's [Material] when a pointer is hovering over it.
final Color? hoverColor; final Color? hoverColor;
/// The splash radius of the circular [Material] ink response.
///
/// If null, then [kRadialReactionRadius] is used.
final double? splashRadius;
/// {@macro flutter.widgets.Focus.focusNode} /// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode; final FocusNode? focusNode;
...@@ -343,6 +351,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin { ...@@ -343,6 +351,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
inactiveColor: inactiveThumbColor, inactiveColor: inactiveThumbColor,
hoverColor: hoverColor, hoverColor: hoverColor,
focusColor: focusColor, focusColor: focusColor,
splashRadius: widget.splashRadius ?? kRadialReactionRadius,
activeThumbImage: widget.activeThumbImage, activeThumbImage: widget.activeThumbImage,
onActiveThumbImageError: widget.onActiveThumbImageError, onActiveThumbImageError: widget.onActiveThumbImageError,
inactiveThumbImage: widget.inactiveThumbImage, inactiveThumbImage: widget.inactiveThumbImage,
...@@ -413,6 +422,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -413,6 +422,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
required this.inactiveColor, required this.inactiveColor,
required this.hoverColor, required this.hoverColor,
required this.focusColor, required this.focusColor,
required this.splashRadius,
required this.activeThumbImage, required this.activeThumbImage,
required this.onActiveThumbImageError, required this.onActiveThumbImageError,
required this.inactiveThumbImage, required this.inactiveThumbImage,
...@@ -433,6 +443,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -433,6 +443,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
final Color inactiveColor; final Color inactiveColor;
final Color hoverColor; final Color hoverColor;
final Color focusColor; final Color focusColor;
final double splashRadius;
final ImageProvider? activeThumbImage; final ImageProvider? activeThumbImage;
final ImageErrorListener? onActiveThumbImageError; final ImageErrorListener? onActiveThumbImageError;
final ImageProvider? inactiveThumbImage; final ImageProvider? inactiveThumbImage;
...@@ -456,6 +467,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -456,6 +467,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
hoverColor: hoverColor, hoverColor: hoverColor,
focusColor: focusColor, focusColor: focusColor,
splashRadius: splashRadius,
activeThumbImage: activeThumbImage, activeThumbImage: activeThumbImage,
onActiveThumbImageError: onActiveThumbImageError, onActiveThumbImageError: onActiveThumbImageError,
inactiveThumbImage: inactiveThumbImage, inactiveThumbImage: inactiveThumbImage,
...@@ -480,6 +492,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -480,6 +492,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
..inactiveColor = inactiveColor ..inactiveColor = inactiveColor
..hoverColor = hoverColor ..hoverColor = hoverColor
..focusColor = focusColor ..focusColor = focusColor
..splashRadius = splashRadius
..activeThumbImage = activeThumbImage ..activeThumbImage = activeThumbImage
..onActiveThumbImageError = onActiveThumbImageError ..onActiveThumbImageError = onActiveThumbImageError
..inactiveThumbImage = inactiveThumbImage ..inactiveThumbImage = inactiveThumbImage
...@@ -515,6 +528,7 @@ class _RenderSwitch extends RenderToggleable { ...@@ -515,6 +528,7 @@ class _RenderSwitch extends RenderToggleable {
required Color inactiveColor, required Color inactiveColor,
required Color hoverColor, required Color hoverColor,
required Color focusColor, required Color focusColor,
required double splashRadius,
required ImageProvider? activeThumbImage, required ImageProvider? activeThumbImage,
required ImageErrorListener? onActiveThumbImageError, required ImageErrorListener? onActiveThumbImageError,
required ImageProvider? inactiveThumbImage, required ImageProvider? inactiveThumbImage,
...@@ -545,6 +559,7 @@ class _RenderSwitch extends RenderToggleable { ...@@ -545,6 +559,7 @@ class _RenderSwitch extends RenderToggleable {
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
hoverColor: hoverColor, hoverColor: hoverColor,
focusColor: focusColor, focusColor: focusColor,
splashRadius: splashRadius,
onChanged: onChanged, onChanged: onChanged,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
hasFocus: hasFocus, hasFocus: hasFocus,
...@@ -668,7 +683,7 @@ class _RenderSwitch extends RenderToggleable { ...@@ -668,7 +683,7 @@ class _RenderSwitch extends RenderToggleable {
super.detach(); super.detach();
} }
double get _trackInnerLength => size.width - 2.0 * kRadialReactionRadius; double get _trackInnerLength => size.width - _kSwitchMinSize;
late HorizontalDragGestureRecognizer _drag; late HorizontalDragGestureRecognizer _drag;
......
...@@ -13,9 +13,6 @@ import 'constants.dart'; ...@@ -13,9 +13,6 @@ import 'constants.dart';
// Duration of the animation that moves the toggle from one state to another. // Duration of the animation that moves the toggle from one state to another.
const Duration _kToggleDuration = Duration(milliseconds: 200); const Duration _kToggleDuration = Duration(milliseconds: 200);
// Radius of the radial reaction over time.
final Animatable<double> _kRadialReactionRadiusTween = Tween<double>(begin: 0.0, end: kRadialReactionRadius);
// Duration of the fade animation for the reaction when focus and hover occur. // Duration of the fade animation for the reaction when focus and hover occur.
const Duration _kReactionFadeDuration = Duration(milliseconds: 50); const Duration _kReactionFadeDuration = Duration(milliseconds: 50);
...@@ -36,6 +33,7 @@ abstract class RenderToggleable extends RenderConstrainedBox { ...@@ -36,6 +33,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
required Color inactiveColor, required Color inactiveColor,
Color? hoverColor, Color? hoverColor,
Color? focusColor, Color? focusColor,
required double splashRadius,
ValueChanged<bool?>? onChanged, ValueChanged<bool?>? onChanged,
required BoxConstraints additionalConstraints, required BoxConstraints additionalConstraints,
required TickerProvider vsync, required TickerProvider vsync,
...@@ -52,6 +50,7 @@ abstract class RenderToggleable extends RenderConstrainedBox { ...@@ -52,6 +50,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
_inactiveColor = inactiveColor, _inactiveColor = inactiveColor,
_hoverColor = hoverColor ?? activeColor.withAlpha(kRadialReactionAlpha), _hoverColor = hoverColor ?? activeColor.withAlpha(kRadialReactionAlpha),
_focusColor = focusColor ?? activeColor.withAlpha(kRadialReactionAlpha), _focusColor = focusColor ?? activeColor.withAlpha(kRadialReactionAlpha),
_splashRadius = splashRadius,
_onChanged = onChanged, _onChanged = onChanged,
_hasFocus = hasFocus, _hasFocus = hasFocus,
_hovering = hovering, _hovering = hovering,
...@@ -331,6 +330,16 @@ abstract class RenderToggleable extends RenderConstrainedBox { ...@@ -331,6 +330,16 @@ abstract class RenderToggleable extends RenderConstrainedBox {
markNeedsPaint(); markNeedsPaint();
} }
/// The splash radius for the radial reaction.
double get splashRadius => _splashRadius;
double _splashRadius;
set splashRadius(double value) {
if (value == _splashRadius)
return;
_splashRadius = value;
markNeedsPaint();
}
/// Called when the control changes value. /// Called when the control changes value.
/// ///
/// If the control is tapped, [onChanged] is called immediately with the new /// If the control is tapped, [onChanged] is called immediately with the new
...@@ -457,9 +466,13 @@ abstract class RenderToggleable extends RenderConstrainedBox { ...@@ -457,9 +466,13 @@ abstract class RenderToggleable extends RenderConstrainedBox {
_reactionFocusFade.value, _reactionFocusFade.value,
)!; )!;
final Offset center = Offset.lerp(_downPosition ?? origin, origin, _reaction.value)!; final Offset center = Offset.lerp(_downPosition ?? origin, origin, _reaction.value)!;
final Animatable<double> radialReactionRadiusTween = Tween<double>(
begin: 0.0,
end: splashRadius,
);
final double reactionRadius = hasFocus || hovering final double reactionRadius = hasFocus || hovering
? kRadialReactionRadius ? splashRadius
: _kRadialReactionRadiusTween.evaluate(_reaction); : radialReactionRadiusTween.evaluate(_reaction);
if (reactionRadius > 0.0) { if (reactionRadius > 0.0) {
canvas.drawCircle(center + offset, reactionRadius, reactionPaint); canvas.drawCircle(center + offset, reactionRadius, reactionPaint);
} }
......
...@@ -470,6 +470,34 @@ void main() { ...@@ -470,6 +470,34 @@ void main() {
); );
}); });
testWidgets('Checkbox with splash radius set', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const double splashRadius = 30;
Widget buildApp() {
return MaterialApp(
home: Material(
child: Center(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return Checkbox(
value: false,
onChanged: (bool? newValue) {},
focusColor: Colors.orange[500],
autofocus: true,
splashRadius: splashRadius,
);
}),
),
),
);
}
await tester.pumpWidget(buildApp());
await tester.pumpAndSettle();
expect(
Material.of(tester.element(find.byType(Checkbox))),
paints..circle(color: Colors.orange[500], radius: splashRadius)
);
});
testWidgets('Checkbox can be hovered and has correct hover color', (WidgetTester tester) async { testWidgets('Checkbox can be hovered and has correct hover color', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
bool? value = true; bool? value = true;
......
...@@ -356,6 +356,42 @@ void main() { ...@@ -356,6 +356,42 @@ void main() {
); );
}); });
testWidgets('Radio with splash radius set', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const double splashRadius = 30;
Widget buildApp() {
return MaterialApp(
home: Material(
child: Center(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return Container(
width: 100,
height: 100,
color: Colors.white,
child: Radio<int>(
value: 0,
onChanged: (int? newValue) {},
focusColor: Colors.orange[500],
autofocus: true,
groupValue: 0,
splashRadius: splashRadius,
),
);
}),
),
),
);
}
await tester.pumpWidget(buildApp());
await tester.pumpAndSettle();
expect(
Material.of(tester.element(
find.byWidgetPredicate((Widget widget) => widget is Radio<int>),
)),
paints..circle(color: Colors.orange[500], radius: splashRadius)
);
});
testWidgets('Radio is focusable and has correct focus color', (WidgetTester tester) async { testWidgets('Radio is focusable and has correct focus color', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'Radio'); final FocusNode focusNode = FocusNode(debugLabel: 'Radio');
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
......
...@@ -797,6 +797,34 @@ void main() { ...@@ -797,6 +797,34 @@ void main() {
); );
}); });
testWidgets('Switch with splash radius set', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const double splashRadius = 30;
Widget buildApp() {
return MaterialApp(
home: Material(
child: Center(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return Switch(
value: true,
onChanged: (bool newValue) {},
focusColor: Colors.orange[500],
autofocus: true,
splashRadius: splashRadius,
);
}),
),
),
);
}
await tester.pumpWidget(buildApp());
await tester.pumpAndSettle();
expect(
Material.of(tester.element(find.byType(Switch))),
paints..circle(color: Colors.orange[500], radius: splashRadius)
);
});
testWidgets('Switch can be hovered and has correct hover color', (WidgetTester tester) async { testWidgets('Switch can be hovered and has correct hover color', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
bool value = true; bool value = true;
......
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