Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ListTile accentColor dependency #77004

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/benchmarks/test_apps/stocks/lib/main.dart
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dev/benchmarks/test_apps/stocks/test/icon_color_test.dart
Expand Up @@ -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
});
Expand Down
22 changes: 7 additions & 15 deletions packages/flutter/lib/src/material/list_tile.dart
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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;
}

Expand Down
49 changes: 49 additions & 0 deletions packages/flutter/test/material/list_tile_test.dart
Expand Up @@ -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);
});
}