From 490364059d2f45fcbf771596f137cab6be8336fb Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 1 Mar 2021 08:34:05 -0800 Subject: [PATCH] Removed SwitchListTile accentColor dependency (#76909) --- .../lib/src/material/switch_list_tile.dart | 12 ++++--- .../test/material/switch_list_tile_test.dart | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 5ff1058dd3..5862cf39b9 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -35,10 +35,12 @@ enum _SwitchListTileType { material, adaptive } /// 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 -/// appear selected when the switch is on, pass the same value to both. +/// 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]; to have the list tile appear selected when the +/// switch button is on, use the same value for both. /// /// The switch is shown on the right by default in left-to-right languages (i.e. /// in the [ListTile.trailing] slot) which can be changed using [controlAffinity]. @@ -503,7 +505,7 @@ class SwitchListTile 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/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart index eb03860d4b..03d70578d9 100644 --- a/packages/flutter/test/material/switch_list_tile_test.dart +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; @@ -397,4 +398,38 @@ void main() { expect(find.byType(Material), paints..path(color: selectedTileColor)); }); + testWidgets('SwitchListTile selected item text Color', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/pull/76909 + + const Color activeColor = Color(0xff00ff00); + + Widget buildFrame({ Color? activeColor, Color? toggleableActiveColor }) { + return MaterialApp( + theme: ThemeData.light().copyWith( + toggleableActiveColor: toggleableActiveColor, + ), + home: Scaffold( + body: Center( + child: SwitchListTile( + 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); + }); }