[SwitchListTile and CheckboxListTile] Adds selectedTileColor property (#68358)
This commit is contained in:
@@ -274,6 +274,7 @@ class CheckboxListTile extends StatelessWidget {
|
||||
this.contentPadding,
|
||||
this.tristate = false,
|
||||
this.shape,
|
||||
this.selectedTileColor,
|
||||
}) : assert(tristate != null),
|
||||
assert(tristate || value != null),
|
||||
assert(isThreeLine != null),
|
||||
@@ -388,6 +389,9 @@ class CheckboxListTile extends StatelessWidget {
|
||||
/// {@macro flutter.material.ListTile.shape}
|
||||
final ShapeBorder? shape;
|
||||
|
||||
/// If non-null, defines the background color when [CheckboxListTile.selected] is true.
|
||||
final Color? selectedTileColor;
|
||||
|
||||
void _handleValueChange() {
|
||||
assert(onChanged != null);
|
||||
switch (value) {
|
||||
@@ -442,6 +446,7 @@ class CheckboxListTile extends StatelessWidget {
|
||||
autofocus: autofocus,
|
||||
contentPadding: contentPadding,
|
||||
shape: shape,
|
||||
selectedTileColor: selectedTileColor,
|
||||
tileColor: tileColor,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -275,6 +275,7 @@ class SwitchListTile extends StatelessWidget {
|
||||
this.autofocus = false,
|
||||
this.controlAffinity = ListTileControlAffinity.platform,
|
||||
this.shape,
|
||||
this.selectedTileColor,
|
||||
}) : _switchListTileType = _SwitchListTileType.material,
|
||||
assert(value != null),
|
||||
assert(isThreeLine != null),
|
||||
@@ -312,6 +313,7 @@ class SwitchListTile extends StatelessWidget {
|
||||
this.autofocus = false,
|
||||
this.controlAffinity = ListTileControlAffinity.platform,
|
||||
this.shape,
|
||||
this.selectedTileColor,
|
||||
}) : _switchListTileType = _SwitchListTileType.adaptive,
|
||||
assert(value != null),
|
||||
assert(isThreeLine != null),
|
||||
@@ -445,6 +447,9 @@ class SwitchListTile extends StatelessWidget {
|
||||
/// {@macro flutter.material.ListTile.shape}
|
||||
final ShapeBorder? shape;
|
||||
|
||||
/// If non-null, defines the background color when [SwitchListTile.selected] is true.
|
||||
final Color? selectedTileColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget control;
|
||||
@@ -506,6 +511,7 @@ class SwitchListTile extends StatelessWidget {
|
||||
enabled: onChanged != null,
|
||||
onTap: onChanged != null ? () { onChanged!(!value); } : null,
|
||||
selected: selected,
|
||||
selectedTileColor: selectedTileColor,
|
||||
autofocus: autofocus,
|
||||
shape: shape,
|
||||
tileColor: tileColor,
|
||||
|
||||
@@ -259,4 +259,25 @@ void main() {
|
||||
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
|
||||
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() {
|
||||
final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox));
|
||||
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));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user