From b91b1644d9ec9f631af7dad103cd7eaf92c13eb2 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 1 Mar 2021 08:32:05 -0800 Subject: [PATCH] Removed CheckboxListTile accentColor dependency (#76908) --- .../lib/src/material/checkbox_list_tile.dart | 9 ++--- .../material/checkbox_list_tile_test.dart | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 892045fa2c..a9899e4e3d 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -26,9 +26,10 @@ import 'theme_data.dart'; /// those of the same name on [ListTile]. /// /// The [selected] property on this widget is similar to the [ListTile.selected] -/// property, but the color used is that described by [activeColor], if any, -/// defaulting to the accent color of the current [Theme]. No effort is made to -/// coordinate the [selected] state and the [value] state; to have the list tile +/// property. This tile's [activeColor] is used for the selected item's text color, or +/// the theme's [ThemeData.toggleableActiveColor] if [activeColor] is null. +/// +/// This widget does not coordinate the [selected] state and the [value] state; to have the list tile /// appear selected when the checkbox is checked, pass the same value to both. /// /// The checkbox is shown on the right by default in left-to-right languages @@ -432,7 +433,7 @@ class CheckboxListTile extends StatelessWidget { } return MergeSemantics( child: ListTileTheme.merge( - selectedColor: activeColor ?? Theme.of(context).accentColor, + selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor, child: ListTile( leading: leading, title: title, diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index f476c59264..0361a2fcb2 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import '../rendering/mock_canvas.dart'; @@ -283,4 +284,39 @@ void main() { expect(find.byType(Material), paints..path(color: selectedTileColor)); }); + + testWidgets('CheckboxListTile selected item text Color', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/pull/76908 + + const Color activeColor = Color(0xff00ff00); + + Widget buildFrame({ Color? activeColor, Color? toggleableActiveColor }) { + return MaterialApp( + theme: ThemeData.light().copyWith( + toggleableActiveColor: toggleableActiveColor, + ), + home: Scaffold( + body: Center( + child: CheckboxListTile( + activeColor: activeColor, + selected: true, + title: const Text('title'), + value: true, + onChanged: (bool? value) { }, + ), + ), + ), + ); + } + + Color? textColor(String text) { + return tester.renderObject(find.text(text)).text.style?.color; + } + + await tester.pumpWidget(buildFrame(toggleableActiveColor: activeColor)); + expect(textColor('title'), activeColor); + + await tester.pumpWidget(buildFrame(activeColor: activeColor)); + expect(textColor('title'), activeColor); + }); }