diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 4b92c3317a..578fe552ed 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -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, ), ), diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 08bfb68a76..8764637ec1 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -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, diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index d69a7f6bbb..d22e3dfbb4 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -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)); + }); } diff --git a/packages/flutter/test/material/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart index a8919ceecc..f40c7cf49a 100644 --- a/packages/flutter/test/material/switch_list_tile_test.dart +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -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)); + }); + }