diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 8443784573f..d42d6989c50 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -3010,11 +3010,14 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData { @override CupertinoThemeData resolveFrom(BuildContext context) { - // Only the cupertino override theme part will be resolved. + // Only the cupertino override theme part will be resolved, as well as the + // default text theme. // If the color comes from the material theme it's not resolved. + final NoDefaultCupertinoThemeData cupertinoOverrideThemeWithTextTheme = _cupertinoOverrideTheme + .copyWith(textTheme: textTheme); return MaterialBasedCupertinoThemeData._( _materialTheme, - _cupertinoOverrideTheme.resolveFrom(context), + cupertinoOverrideThemeWithTextTheme.resolveFrom(context), ); } } diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index ee9b9aeedd8..ac3d6b8d9f0 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/theme_test.dart @@ -758,6 +758,30 @@ void main() { expect(CupertinoTheme.brightnessOf(context!), Brightness.light); }); + testWidgets('Cupertino widgets correctly get the right text theme in dark mode', ( + WidgetTester tester, + ) async { + final GlobalKey textFieldKey = GlobalKey(); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData.dark(), + home: Scaffold(body: CupertinoTextField(key: textFieldKey)), + ), + ); + await tester.pumpAndSettle(); + + final EditableTextState state = tester.state(find.byType(EditableText)); + + // Default CupertinoTextStyle color is a CupertinoDynamicColor. + final CupertinoThemeData cupertinoThemeData = CupertinoTheme.of(textFieldKey.currentContext!); + expect(cupertinoThemeData.textTheme.textStyle.color, isA()); + final CupertinoDynamicColor themeTextStyleColor = + cupertinoThemeData.textTheme.textStyle.color! as CupertinoDynamicColor; + + // The value of the textfield's color should resolve to the theme's dark color. + expect(state.widget.style.color?.value, equals(themeTextStyleColor.darkColor.value)); + }); + testWidgets('Material2 - Can override material theme', (WidgetTester tester) async { final CupertinoThemeData themeM2 = await testTheme( tester,