mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[M3] Add ListTile's iconColor property support for icon buttons (#120075)
* add icon button property override * list tile changes * add imports * add newlines * whitespace
This commit is contained in:
parent
47a0674651
commit
3c3c9a1bd9
@ -12,6 +12,8 @@ import 'colors.dart';
|
||||
import 'constants.dart';
|
||||
import 'debug.dart';
|
||||
import 'divider.dart';
|
||||
import 'icon_button.dart';
|
||||
import 'icon_button_theme.dart';
|
||||
import 'ink_decoration.dart';
|
||||
import 'ink_well.dart';
|
||||
import 'list_tile_theme.dart';
|
||||
@ -692,6 +694,9 @@ class ListTile extends StatelessWidget {
|
||||
?? resolveColor(theme.listTileTheme.textColor, theme.listTileTheme.selectedColor, theme.listTileTheme.textColor)
|
||||
?? resolveColor(defaults.textColor, defaults.selectedColor, defaults.textColor, theme.disabledColor);
|
||||
final IconThemeData iconThemeData = IconThemeData(color: effectiveIconColor);
|
||||
final IconButtonThemeData iconButtonThemeData = IconButtonThemeData(
|
||||
style: IconButton.styleFrom(foregroundColor: effectiveIconColor),
|
||||
);
|
||||
|
||||
TextStyle? leadingAndTrailingStyle;
|
||||
if (leading != null || trailing != null) {
|
||||
@ -791,21 +796,24 @@ class ListTile extends StatelessWidget {
|
||||
minimum: resolvedContentPadding,
|
||||
child: IconTheme.merge(
|
||||
data: iconThemeData,
|
||||
child: _ListTile(
|
||||
leading: leadingIcon,
|
||||
title: titleText,
|
||||
subtitle: subtitleText,
|
||||
trailing: trailingIcon,
|
||||
isDense: _isDenseLayout(theme, tileTheme),
|
||||
visualDensity: visualDensity ?? tileTheme.visualDensity ?? theme.visualDensity,
|
||||
isThreeLine: isThreeLine,
|
||||
textDirection: textDirection,
|
||||
titleBaselineType: titleStyle.textBaseline ?? defaults.titleTextStyle!.textBaseline!,
|
||||
subtitleBaselineType: subtitleStyle?.textBaseline ?? defaults.subtitleTextStyle!.textBaseline!,
|
||||
horizontalTitleGap: horizontalTitleGap ?? tileTheme.horizontalTitleGap ?? 16,
|
||||
minVerticalPadding: minVerticalPadding ?? tileTheme.minVerticalPadding ?? defaults.minVerticalPadding!,
|
||||
minLeadingWidth: minLeadingWidth ?? tileTheme.minLeadingWidth ?? defaults.minLeadingWidth!,
|
||||
material3: theme.useMaterial3,
|
||||
child: IconButtonTheme(
|
||||
data: iconButtonThemeData,
|
||||
child: _ListTile(
|
||||
leading: leadingIcon,
|
||||
title: titleText,
|
||||
subtitle: subtitleText,
|
||||
trailing: trailingIcon,
|
||||
isDense: _isDenseLayout(theme, tileTheme),
|
||||
visualDensity: visualDensity ?? tileTheme.visualDensity ?? theme.visualDensity,
|
||||
isThreeLine: isThreeLine,
|
||||
textDirection: textDirection,
|
||||
titleBaselineType: titleStyle.textBaseline ?? defaults.titleTextStyle!.textBaseline!,
|
||||
subtitleBaselineType: subtitleStyle?.textBaseline ?? defaults.subtitleTextStyle!.textBaseline!,
|
||||
horizontalTitleGap: horizontalTitleGap ?? tileTheme.horizontalTitleGap ?? 16,
|
||||
minVerticalPadding: minVerticalPadding ?? tileTheme.minVerticalPadding ?? defaults.minVerticalPadding!,
|
||||
minLeadingWidth: minLeadingWidth ?? tileTheme.minLeadingWidth ?? defaults.minLeadingWidth!,
|
||||
material3: theme.useMaterial3,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2150,6 +2150,50 @@ void main() {
|
||||
expect(iconColor(leadingKey), selectedColor);
|
||||
});
|
||||
|
||||
testWidgets('ListTile.iconColor respects iconColor property with icon buttons Material 3 in presence of IconButtonTheme override', (WidgetTester tester) async {
|
||||
const Color iconButtonThemeColor = Colors.blue;
|
||||
const Color listTileIconColor = Colors.green;
|
||||
const Icon leadingIcon = Icon(Icons.favorite);
|
||||
const Icon trailingIcon = Icon(Icons.close);
|
||||
|
||||
Widget buildFrame() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
iconButtonTheme: IconButtonThemeData(
|
||||
style: IconButton.styleFrom(
|
||||
foregroundColor: iconButtonThemeColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return ListTile(
|
||||
iconColor: listTileIconColor,
|
||||
leading: IconButton(icon: leadingIcon, onPressed: () {}),
|
||||
trailing: IconButton(icon: trailingIcon, onPressed: () {}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TextStyle? getIconStyle(WidgetTester tester, IconData icon) =>
|
||||
tester.widget<RichText>(find.descendant(
|
||||
of: find.byIcon(icon),
|
||||
matching: find.byType(RichText),
|
||||
),
|
||||
).text.style;
|
||||
|
||||
await tester.pumpWidget(buildFrame());
|
||||
expect(getIconStyle(tester, leadingIcon.icon!)?.color, listTileIconColor);
|
||||
expect(getIconStyle(tester, trailingIcon.icon!)?.color, listTileIconColor);
|
||||
});
|
||||
|
||||
testWidgets('ListTile.dense does not throw assertion', (WidgetTester tester) async {
|
||||
// This is a regression test for https://github.com/flutter/flutter/pull/116908
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user