Unverified Commit 49ff0d99 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Removed ListTile accentColor dependency (#77004)

parent d39d4505
......@@ -64,7 +64,7 @@ class StocksAppState extends State<StocksApp> {
case StockMode.pessimistic:
return ThemeData(
brightness: Brightness.dark,
accentColor: Colors.redAccent,
primarySwatch: Colors.purple,
);
}
assert(_configuration.stockMode != null);
......
......@@ -83,7 +83,7 @@ void main() {
await tester.pump(const Duration(seconds: 5)); // end the transition
// check the color of the icon - dark mode
checkIconColor(tester, 'Stock List', Colors.redAccent); // theme accent color
checkIconColor(tester, 'Stock List', Colors.purple); // theme primary color
checkIconColor(tester, 'Account Balance', Colors.white38); // disabled
checkIconColor(tester, 'About', Colors.white); // enabled
});
......
......@@ -788,11 +788,6 @@ class ListTile extends StatelessWidget {
///
/// When [enabled] is false, the text color is set to [ThemeData.disabledColor].
///
/// When [selected] is true, the text color is set to [ListTileTheme.selectedColor]
/// if it's not null. If [ListTileTheme.selectedColor] is null, the text color
/// is set to [ThemeData.primaryColor] when [ThemeData.brightness] is
/// [Brightness.light] and to [ThemeData.accentColor] when it is [Brightness.dark].
///
/// When [selected] is false, the text color is set to [ListTileTheme.textColor]
/// if it's not null and to [TextTheme.caption]'s color if [ListTileTheme.textColor]
/// is null.
......@@ -1019,9 +1014,11 @@ class ListTile extends StatelessWidget {
switch (theme.brightness) {
case Brightness.light:
return selected ? theme.primaryColor : Colors.black45;
// For the sake of backwards compatibility, the default for unselected
// tiles is Colors.black45 rather than colorScheme.onSurface.withAlpha(0x73).
return selected ? theme.colorScheme.primary : Colors.black45;
case Brightness.dark:
return selected ? theme.accentColor : null; // null - use current icon theme color
return selected ? theme.colorScheme.primary : null; // null - use current icon theme color
}
}
......@@ -1035,14 +1032,9 @@ class ListTile extends StatelessWidget {
if (!selected && tileTheme?.textColor != null)
return tileTheme!.textColor;
if (selected) {
switch (theme.brightness) {
case Brightness.light:
return theme.primaryColor;
case Brightness.dark:
return theme.accentColor;
}
}
if (selected)
return theme.colorScheme.primary;
return defaultColor;
}
......
......@@ -2284,4 +2284,53 @@ void main() {
expect(textColor(leadingKey), theme.disabledColor);
expect(textColor(trailingKey), theme.disabledColor);
});
testWidgets('selected, enabled ListTile default icon color, light and dark themes', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/pull/77004
const ColorScheme lightColorScheme = ColorScheme.light();
const ColorScheme darkColorScheme = ColorScheme.dark();
final Key leadingKey = UniqueKey();
final Key trailingKey = UniqueKey();
Widget buildFrame({ required Brightness brightness, required bool selected }) {
final ThemeData theme = brightness == Brightness.light
? ThemeData.from(colorScheme: const ColorScheme.light())
: ThemeData.from(colorScheme: const ColorScheme.dark());
return MaterialApp(
theme: theme,
home: Material(
child: Center(
child: ListTile(
enabled: true,
selected: selected,
leading: TestIcon(key: leadingKey),
trailing: TestIcon(key: trailingKey),
),
),
),
);
}
Color iconColor(Key key) => tester.state<TestIconState>(find.byKey(key)).iconTheme.color!;
await tester.pumpWidget(buildFrame(brightness: Brightness.light, selected: true));
expect(iconColor(leadingKey), lightColorScheme.primary);
expect(iconColor(trailingKey), lightColorScheme.primary);
await tester.pumpWidget(buildFrame(brightness: Brightness.light, selected: false));
expect(iconColor(leadingKey), Colors.black45);
expect(iconColor(trailingKey), Colors.black45);
await tester.pumpWidget(buildFrame(brightness: Brightness.dark, selected: true));
await tester.pumpAndSettle(); // Animated theme change
expect(iconColor(leadingKey), darkColorScheme.primary);
expect(iconColor(trailingKey), darkColorScheme.primary);
// For this configuration, ListTile defers to the default IconTheme.
// The default dark theme's IconTheme has color:white
await tester.pumpWidget(buildFrame(brightness: Brightness.dark, selected: false));
expect(iconColor(leadingKey), Colors.white);
expect(iconColor(trailingKey), Colors.white);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment