mirror of
https://github.com/flutter/flutter.git
synced 2026-01-21 13:16:40 +08:00
Fix IconButton.color overrided by IconButtomTheme (#174515)
## Description This PR fixes IconButton icon color resolution. ## Before The IconButton.color property does not take precedence over the ambient `IconButtonTheme` ## After The IconButton.color property overrides the ambient `IconButtonTheme`. ## Related Issue Fixes [SnackBar closeIconColor does not respect widget override](https://github.com/flutter/flutter/issues/174472) Fixes [IconButton.color is overidden by IconButtonTheme](https://github.com/flutter/flutter/issues/174511) ## Tests Adds 1 test.
This commit is contained in:
parent
cc0b0471b9
commit
c1ce4e530c
@ -745,7 +745,9 @@ class IconButton extends StatelessWidget {
|
||||
if (style != null) {
|
||||
adjustedStyle = style!.merge(adjustedStyle);
|
||||
}
|
||||
|
||||
if (adjustedStyle.iconColor == null) {
|
||||
adjustedStyle = adjustedStyle.copyWith(iconColor: adjustedStyle.foregroundColor);
|
||||
}
|
||||
Widget effectiveIcon = icon;
|
||||
if ((isSelected ?? false) && selectedIcon != null) {
|
||||
effectiveIcon = selectedIcon!;
|
||||
|
||||
@ -2761,6 +2761,37 @@ void main() {
|
||||
expect(getOverlayColor(tester), paints..rect(color: overlayColor));
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/174511.
|
||||
testWidgets('IconButton.color takes precedence over ambient IconButtonThemeData.iconColor', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Color iconButtonColor = Color(0xFFFF1234);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
iconButtonTheme: const IconButtonThemeData(
|
||||
style: ButtonStyle(
|
||||
iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
|
||||
WidgetState.any: Colors.purple,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add, size: 64),
|
||||
color: iconButtonColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(_iconStyle(tester, Icons.add)?.color, iconButtonColor);
|
||||
});
|
||||
|
||||
group('IconTheme tests in Material 3', () {
|
||||
testWidgets('IconTheme overrides default values in M3', (WidgetTester tester) async {
|
||||
// Theme's IconTheme
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user