Unverified Commit f3562c6f authored by Yash Johri's avatar Yash Johri Committed by GitHub

[SwitchListTile and CheckboxListTile] Adds selectedTileColor property (#68358)

parent 0c63d63b
...@@ -274,6 +274,7 @@ class CheckboxListTile extends StatelessWidget { ...@@ -274,6 +274,7 @@ class CheckboxListTile extends StatelessWidget {
this.contentPadding, this.contentPadding,
this.tristate = false, this.tristate = false,
this.shape, this.shape,
this.selectedTileColor,
}) : assert(tristate != null), }) : assert(tristate != null),
assert(tristate || value != null), assert(tristate || value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
...@@ -388,6 +389,9 @@ class CheckboxListTile extends StatelessWidget { ...@@ -388,6 +389,9 @@ class CheckboxListTile extends StatelessWidget {
/// {@macro flutter.material.ListTile.shape} /// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape; final ShapeBorder? shape;
/// If non-null, defines the background color when [CheckboxListTile.selected] is true.
final Color? selectedTileColor;
void _handleValueChange() { void _handleValueChange() {
assert(onChanged != null); assert(onChanged != null);
switch (value) { switch (value) {
...@@ -442,6 +446,7 @@ class CheckboxListTile extends StatelessWidget { ...@@ -442,6 +446,7 @@ class CheckboxListTile extends StatelessWidget {
autofocus: autofocus, autofocus: autofocus,
contentPadding: contentPadding, contentPadding: contentPadding,
shape: shape, shape: shape,
selectedTileColor: selectedTileColor,
tileColor: tileColor, tileColor: tileColor,
), ),
), ),
......
...@@ -275,6 +275,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -275,6 +275,7 @@ class SwitchListTile extends StatelessWidget {
this.autofocus = false, this.autofocus = false,
this.controlAffinity = ListTileControlAffinity.platform, this.controlAffinity = ListTileControlAffinity.platform,
this.shape, this.shape,
this.selectedTileColor,
}) : _switchListTileType = _SwitchListTileType.material, }) : _switchListTileType = _SwitchListTileType.material,
assert(value != null), assert(value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
...@@ -312,6 +313,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -312,6 +313,7 @@ class SwitchListTile extends StatelessWidget {
this.autofocus = false, this.autofocus = false,
this.controlAffinity = ListTileControlAffinity.platform, this.controlAffinity = ListTileControlAffinity.platform,
this.shape, this.shape,
this.selectedTileColor,
}) : _switchListTileType = _SwitchListTileType.adaptive, }) : _switchListTileType = _SwitchListTileType.adaptive,
assert(value != null), assert(value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
...@@ -445,6 +447,9 @@ class SwitchListTile extends StatelessWidget { ...@@ -445,6 +447,9 @@ class SwitchListTile extends StatelessWidget {
/// {@macro flutter.material.ListTile.shape} /// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape; final ShapeBorder? shape;
/// If non-null, defines the background color when [SwitchListTile.selected] is true.
final Color? selectedTileColor;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget control; final Widget control;
...@@ -506,6 +511,7 @@ class SwitchListTile extends StatelessWidget { ...@@ -506,6 +511,7 @@ class SwitchListTile extends StatelessWidget {
enabled: onChanged != null, enabled: onChanged != null,
onTap: onChanged != null ? () { onChanged!(!value); } : null, onTap: onChanged != null ? () { onChanged!(!value); } : null,
selected: selected, selected: selected,
selectedTileColor: selectedTileColor,
autofocus: autofocus, autofocus: autofocus,
shape: shape, shape: shape,
tileColor: tileColor, tileColor: tileColor,
......
...@@ -259,4 +259,25 @@ void main() { ...@@ -259,4 +259,25 @@ void main() {
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(tileColor)); expect(coloredBox.color, equals(tileColor));
}); });
testWidgets('CheckboxListTile respects selectedTileColor', (WidgetTester tester) async {
const Color selectedTileColor = Colors.black;
await tester.pumpWidget(
wrap(
child: const Center(
child: CheckboxListTile(
value: false,
onChanged: null,
title: Text('Title'),
selected: true,
selectedTileColor: selectedTileColor,
),
),
),
);
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(selectedTileColor));
});
} }
...@@ -377,4 +377,26 @@ void main() { ...@@ -377,4 +377,26 @@ void main() {
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox)); final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, tileColor); expect(coloredBox.color, tileColor);
}); });
testWidgets('SwitchListTile respects selectedTileColor', (WidgetTester tester) async {
const Color selectedTileColor = Colors.black;
await tester.pumpWidget(
wrap(
child: const Center(
child: SwitchListTile(
value: false,
onChanged: null,
title: Text('Title'),
selected: true,
selectedTileColor: selectedTileColor,
),
),
),
);
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
expect(coloredBox.color, equals(selectedTileColor));
});
} }
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