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 'constants.dart';
|
||||||
import 'debug.dart';
|
import 'debug.dart';
|
||||||
import 'divider.dart';
|
import 'divider.dart';
|
||||||
|
import 'icon_button.dart';
|
||||||
|
import 'icon_button_theme.dart';
|
||||||
import 'ink_decoration.dart';
|
import 'ink_decoration.dart';
|
||||||
import 'ink_well.dart';
|
import 'ink_well.dart';
|
||||||
import 'list_tile_theme.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(theme.listTileTheme.textColor, theme.listTileTheme.selectedColor, theme.listTileTheme.textColor)
|
||||||
?? resolveColor(defaults.textColor, defaults.selectedColor, defaults.textColor, theme.disabledColor);
|
?? resolveColor(defaults.textColor, defaults.selectedColor, defaults.textColor, theme.disabledColor);
|
||||||
final IconThemeData iconThemeData = IconThemeData(color: effectiveIconColor);
|
final IconThemeData iconThemeData = IconThemeData(color: effectiveIconColor);
|
||||||
|
final IconButtonThemeData iconButtonThemeData = IconButtonThemeData(
|
||||||
|
style: IconButton.styleFrom(foregroundColor: effectiveIconColor),
|
||||||
|
);
|
||||||
|
|
||||||
TextStyle? leadingAndTrailingStyle;
|
TextStyle? leadingAndTrailingStyle;
|
||||||
if (leading != null || trailing != null) {
|
if (leading != null || trailing != null) {
|
||||||
@ -791,21 +796,24 @@ class ListTile extends StatelessWidget {
|
|||||||
minimum: resolvedContentPadding,
|
minimum: resolvedContentPadding,
|
||||||
child: IconTheme.merge(
|
child: IconTheme.merge(
|
||||||
data: iconThemeData,
|
data: iconThemeData,
|
||||||
child: _ListTile(
|
child: IconButtonTheme(
|
||||||
leading: leadingIcon,
|
data: iconButtonThemeData,
|
||||||
title: titleText,
|
child: _ListTile(
|
||||||
subtitle: subtitleText,
|
leading: leadingIcon,
|
||||||
trailing: trailingIcon,
|
title: titleText,
|
||||||
isDense: _isDenseLayout(theme, tileTheme),
|
subtitle: subtitleText,
|
||||||
visualDensity: visualDensity ?? tileTheme.visualDensity ?? theme.visualDensity,
|
trailing: trailingIcon,
|
||||||
isThreeLine: isThreeLine,
|
isDense: _isDenseLayout(theme, tileTheme),
|
||||||
textDirection: textDirection,
|
visualDensity: visualDensity ?? tileTheme.visualDensity ?? theme.visualDensity,
|
||||||
titleBaselineType: titleStyle.textBaseline ?? defaults.titleTextStyle!.textBaseline!,
|
isThreeLine: isThreeLine,
|
||||||
subtitleBaselineType: subtitleStyle?.textBaseline ?? defaults.subtitleTextStyle!.textBaseline!,
|
textDirection: textDirection,
|
||||||
horizontalTitleGap: horizontalTitleGap ?? tileTheme.horizontalTitleGap ?? 16,
|
titleBaselineType: titleStyle.textBaseline ?? defaults.titleTextStyle!.textBaseline!,
|
||||||
minVerticalPadding: minVerticalPadding ?? tileTheme.minVerticalPadding ?? defaults.minVerticalPadding!,
|
subtitleBaselineType: subtitleStyle?.textBaseline ?? defaults.subtitleTextStyle!.textBaseline!,
|
||||||
minLeadingWidth: minLeadingWidth ?? tileTheme.minLeadingWidth ?? defaults.minLeadingWidth!,
|
horizontalTitleGap: horizontalTitleGap ?? tileTheme.horizontalTitleGap ?? 16,
|
||||||
material3: theme.useMaterial3,
|
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);
|
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 {
|
testWidgets('ListTile.dense does not throw assertion', (WidgetTester tester) async {
|
||||||
// This is a regression test for https://github.com/flutter/flutter/pull/116908
|
// This is a regression test for https://github.com/flutter/flutter/pull/116908
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user