Commit 4e235c0c authored by Sahel Lucas's avatar Sahel Lucas Committed by Hans Muller

Add Checkbox checkIcon color parameter #26808

The new parameter defines the color of the checkbox's check mark. Default is (still) white.
parent d5b64806
...@@ -59,6 +59,7 @@ class Checkbox extends StatefulWidget { ...@@ -59,6 +59,7 @@ class Checkbox extends StatefulWidget {
this.tristate = false, this.tristate = false,
@required this.onChanged, @required this.onChanged,
this.activeColor, this.activeColor,
this.checkColor,
this.materialTapTargetSize, this.materialTapTargetSize,
}) : assert(tristate != null), }) : assert(tristate != null),
assert(tristate || value != null), assert(tristate || value != null),
...@@ -103,6 +104,11 @@ class Checkbox extends StatefulWidget { ...@@ -103,6 +104,11 @@ class Checkbox extends StatefulWidget {
/// Defaults to [ThemeData.toggleableActiveColor]. /// Defaults to [ThemeData.toggleableActiveColor].
final Color activeColor; final Color activeColor;
/// The color to use for the check icon when this checkbox is checked
///
/// Defaults to Color(0xFFFFFFFF)
final Color checkColor;
/// If true the checkbox's [value] can be true, false, or null. /// If true the checkbox's [value] can be true, false, or null.
/// ///
/// Checkbox displays a dash when its value is null. /// Checkbox displays a dash when its value is null.
...@@ -150,6 +156,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin { ...@@ -150,6 +156,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
value: widget.value, value: widget.value,
tristate: widget.tristate, tristate: widget.tristate,
activeColor: widget.activeColor ?? themeData.toggleableActiveColor, activeColor: widget.activeColor ?? themeData.toggleableActiveColor,
checkColor: widget.checkColor ?? const Color(0xFFFFFFFF),
inactiveColor: widget.onChanged != null ? themeData.unselectedWidgetColor : themeData.disabledColor, inactiveColor: widget.onChanged != null ? themeData.unselectedWidgetColor : themeData.disabledColor,
onChanged: widget.onChanged, onChanged: widget.onChanged,
additionalConstraints: additionalConstraints, additionalConstraints: additionalConstraints,
...@@ -164,6 +171,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -164,6 +171,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
@required this.value, @required this.value,
@required this.tristate, @required this.tristate,
@required this.activeColor, @required this.activeColor,
@required this.checkColor,
@required this.inactiveColor, @required this.inactiveColor,
@required this.onChanged, @required this.onChanged,
@required this.vsync, @required this.vsync,
...@@ -178,6 +186,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -178,6 +186,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
final bool value; final bool value;
final bool tristate; final bool tristate;
final Color activeColor; final Color activeColor;
final Color checkColor;
final Color inactiveColor; final Color inactiveColor;
final ValueChanged<bool> onChanged; final ValueChanged<bool> onChanged;
final TickerProvider vsync; final TickerProvider vsync;
...@@ -188,6 +197,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -188,6 +197,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
value: value, value: value,
tristate: tristate, tristate: tristate,
activeColor: activeColor, activeColor: activeColor,
checkColor: checkColor,
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
onChanged: onChanged, onChanged: onChanged,
vsync: vsync, vsync: vsync,
...@@ -200,6 +210,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -200,6 +210,7 @@ class _CheckboxRenderObjectWidget extends LeafRenderObjectWidget {
..value = value ..value = value
..tristate = tristate ..tristate = tristate
..activeColor = activeColor ..activeColor = activeColor
..checkColor = checkColor
..inactiveColor = inactiveColor ..inactiveColor = inactiveColor
..onChanged = onChanged ..onChanged = onChanged
..additionalConstraints = additionalConstraints ..additionalConstraints = additionalConstraints
...@@ -216,6 +227,7 @@ class _RenderCheckbox extends RenderToggleable { ...@@ -216,6 +227,7 @@ class _RenderCheckbox extends RenderToggleable {
bool value, bool value,
bool tristate, bool tristate,
Color activeColor, Color activeColor,
this.checkColor,
Color inactiveColor, Color inactiveColor,
BoxConstraints additionalConstraints, BoxConstraints additionalConstraints,
ValueChanged<bool> onChanged, ValueChanged<bool> onChanged,
...@@ -232,6 +244,7 @@ class _RenderCheckbox extends RenderToggleable { ...@@ -232,6 +244,7 @@ class _RenderCheckbox extends RenderToggleable {
); );
bool _oldValue; bool _oldValue;
Color checkColor;
@override @override
set value(bool newValue) { set value(bool newValue) {
...@@ -270,7 +283,7 @@ class _RenderCheckbox extends RenderToggleable { ...@@ -270,7 +283,7 @@ class _RenderCheckbox extends RenderToggleable {
// White stroke used to paint the check and dash. // White stroke used to paint the check and dash.
void _initStrokePaint(Paint paint) { void _initStrokePaint(Paint paint) {
paint paint
..color = const Color(0xFFFFFFFF) ..color = checkColor
..style = PaintingStyle.stroke ..style = PaintingStyle.stroke
..strokeWidth = _kStrokeWidth; ..strokeWidth = _kStrokeWidth;
} }
......
...@@ -336,4 +336,32 @@ void main() { ...@@ -336,4 +336,32 @@ void main() {
expect(getCheckboxRenderer(), paints..line()); // null is rendered as a line (a "dash") expect(getCheckboxRenderer(), paints..line()); // null is rendered as a line (a "dash")
}); });
testWidgets('CheckBox color rendering', (WidgetTester tester) async {
Widget buildFrame(Color color) {
return Material(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Checkbox(
value: true,
checkColor: color,
onChanged: (bool value) { },
);
},
),
);
}
RenderToggleable getCheckboxRenderer() {
return tester.renderObject<RenderToggleable>(find.byType(Checkbox));
}
await tester.pumpWidget(buildFrame(null));
await tester.pumpAndSettle();
expect(getCheckboxRenderer(), paints..path(color: const Color(0xFFFFFFFF))); // paints's color is 0xFFFFFFFF (default color)
await tester.pumpWidget(buildFrame(const Color(0xFF000000)));
await tester.pumpAndSettle();
expect(getCheckboxRenderer(), paints..path(color: const Color(0xFF000000))); // paints's color is 0xFF000000 (params)
});
} }
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