diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index 5debf4bd83..692b8cdb20 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -32,6 +32,10 @@ const double _kCupertinoFocusColorSaturation = 0.835; /// [EdgeInsets.zero], should be used to prevent clipping larger [child] /// widgets. /// +/// Preserves any parent [IconThemeData] but overwrites its [IconThemeData.color] +/// with the [CupertinoThemeData.primaryColor] (or +/// [CupertinoThemeData.primaryContrastingColor] if the button is disabled). +/// /// {@tool dartpad} /// This sample shows produces an enabled and disabled [CupertinoButton] and /// [CupertinoButton.filled]. @@ -291,6 +295,7 @@ class _CupertinoButtonState extends State with SingleTickerProv .toColor(); final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor); + final IconThemeData iconTheme = IconTheme.of(context).copyWith(color: foregroundColor); return MouseRegion( cursor: enabled && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer, @@ -344,7 +349,7 @@ class _CupertinoButtonState extends State with SingleTickerProv child: DefaultTextStyle( style: textStyle, child: IconTheme( - data: IconThemeData(color: foregroundColor), + data: iconTheme, child: widget.child, ), ), diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index dbbc52bb7e..56d7e7e239 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -608,6 +608,34 @@ void main() { expect(focused, isFalse); expect(focusNode.hasFocus, isFalse); }); + + testWidgets('IconThemeData is not replaced by CupertinoButton', (WidgetTester tester) async { + const IconThemeData givenIconTheme = IconThemeData(size: 12.0); + + IconThemeData? actualIconTheme; + + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: IconTheme( + data: givenIconTheme, + child: CupertinoButton( + onPressed: () {}, + child: Builder( + builder: (BuildContext context) { + actualIconTheme = IconTheme.of(context); + + return const Placeholder(); + } + ), + ), + ), + ), + ), + ); + + expect(actualIconTheme?.size, givenIconTheme.size); + }); } Widget boilerplate({ required Widget child }) {