From ff85d97ae542025afc0cddff76b673774fc94c0d Mon Sep 17 00:00:00 2001 From: Pedro Massango Date: Thu, 15 Oct 2020 05:27:07 +0100 Subject: [PATCH] Expose the tileColor property (#67135) --- .../lib/src/material/checkbox_list_tile.dart | 5 +++++ .../flutter/lib/src/material/list_tile.dart | 2 ++ .../lib/src/material/switch_list_tile.dart | 6 ++++++ .../material/checkbox_list_tile_test.dart | 20 +++++++++++++++++++ .../test/material/switch_list_tile_test.dart | 20 +++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index e095411a63..4b92c3317a 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -262,6 +262,7 @@ class CheckboxListTile extends StatelessWidget { required this.onChanged, this.activeColor, this.checkColor, + this.tileColor, this.title, this.subtitle, this.isThreeLine = false, @@ -320,6 +321,9 @@ class CheckboxListTile extends StatelessWidget { /// Defaults to Color(0xFFFFFFFF). final Color? checkColor; + /// {@macro flutter.material.ListTile.tileColor} + final Color? tileColor; + /// The primary content of the list tile. /// /// Typically a [Text] widget. @@ -438,6 +442,7 @@ class CheckboxListTile extends StatelessWidget { autofocus: autofocus, contentPadding: contentPadding, shape: shape, + tileColor: tileColor, ), ), ); diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index d94b28fe59..e52a95886c 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -888,10 +888,12 @@ class ListTile extends StatelessWidget { /// {@macro flutter.widgets.Focus.autofocus} final bool autofocus; + /// {@template flutter.material.ListTile.tileColor} /// Defines the background color of `ListTile` when [selected] is false. /// /// When the value is null, the `tileColor` is set to [ListTileTheme.tileColor] /// if it's not null and to [Colors.transparent] if it's null. + /// {@endtemplate} final Color? tileColor; /// Defines the background color of `ListTile` when [selected] is true. diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index a34dd00fb0..08bfb68a76 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -258,6 +258,7 @@ class SwitchListTile extends StatelessWidget { Key? key, required this.value, required this.onChanged, + this.tileColor, this.activeColor, this.activeTrackColor, this.inactiveThumbColor, @@ -294,6 +295,7 @@ class SwitchListTile extends StatelessWidget { Key? key, required this.value, required this.onChanged, + this.tileColor, this.activeColor, this.activeTrackColor, this.inactiveThumbColor, @@ -374,6 +376,9 @@ class SwitchListTile extends StatelessWidget { /// Ignored if created with [SwitchListTile.adaptive]. final Color? inactiveTrackColor; + /// {@macro flutter.material.ListTile.tileColor} + final Color? tileColor; + /// An image to use on the thumb of this switch when the switch is on. final ImageProvider? activeThumbImage; @@ -503,6 +508,7 @@ class SwitchListTile extends StatelessWidget { selected: selected, 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 f97f097355..d69a7f6bbb 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -239,4 +239,24 @@ void main() { expect(tester.widget(find.byType(InkWell)).customBorder, shapeBorder); }); + + testWidgets('CheckboxListTile respects tileColor', (WidgetTester tester) async { + const Color tileColor = Colors.black; + + await tester.pumpWidget( + wrap( + child: const Center( + child: CheckboxListTile( + value: false, + onChanged: null, + title: Text('Title'), + tileColor: tileColor, + ), + ), + ), + ); + + final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox)); + expect(coloredBox.color, equals(tileColor)); + }); } diff --git a/packages/flutter/test/material/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart index be21f71204..a8919ceecc 100644 --- a/packages/flutter/test/material/switch_list_tile_test.dart +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -357,4 +357,24 @@ void main() { expect(tester.widget(find.byType(InkWell)).customBorder, shapeBorder); }); + + testWidgets('SwitchListTile respects tileColor', (WidgetTester tester) async { + const Color tileColor = Colors.red; + + await tester.pumpWidget( + wrap( + child: const Center( + child: SwitchListTile( + value: false, + onChanged: null, + title: Text('Title'), + tileColor: tileColor, + ), + ), + ), + ); + + final ColoredBox coloredBox = tester.firstWidget(find.byType(ColoredBox)); + expect(coloredBox.color, tileColor); + }); }