diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 267fc97865..fa3dd318b7 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -605,7 +605,9 @@ class _CupertinoTextFieldState extends State with AutomaticK if (widget.maxLength != null && widget.maxLengthEnforced) { formatters.add(LengthLimitingTextInputFormatter(widget.maxLength)); } - final TextStyle textStyle = widget.style ?? CupertinoTheme.of(context).textTheme.textStyle; + final CupertinoThemeData themeData = CupertinoTheme.of(context); + final TextStyle textStyle = widget.style ?? themeData.textTheme.textStyle; + final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.brightness; final Widget paddedEditable = Padding( padding: widget.padding, @@ -635,7 +637,7 @@ class _CupertinoTextFieldState extends State with AutomaticK cursorColor: widget.cursorColor, backgroundCursorColor: CupertinoColors.inactiveGray, scrollPadding: widget.scrollPadding, - keyboardAppearance: widget.keyboardAppearance, + keyboardAppearance: keyboardAppearance, ), ), ); diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index ce03c934a6..47c98ddbdb 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -798,6 +798,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien : TextInputAction.done ), textCapitalization: widget.textCapitalization, + keyboardAppearance: widget.keyboardAppearance, ) )..setEditingState(localValue); } diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index f2818e0f84..873a6ec76a 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -1168,4 +1168,52 @@ void main() { ); }, ); + + testWidgets('text field respects keyboardAppearance from theme', (WidgetTester tester) async { + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + + await tester.pumpWidget( + const CupertinoApp( + theme: CupertinoThemeData( + brightness: Brightness.dark, + ), + home: Center( + child: CupertinoTextField(), + ), + ), + ); + + await tester.showKeyboard(find.byType(EditableText)); + final MethodCall setClient = log.first; + expect(setClient.method, 'TextInput.setClient'); + expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.dark'); + }); + + testWidgets('text field can override keyboardAppearance from theme', (WidgetTester tester) async { + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + + await tester.pumpWidget( + const CupertinoApp( + theme: CupertinoThemeData( + brightness: Brightness.dark, + ), + home: Center( + child: CupertinoTextField( + keyboardAppearance: Brightness.light, + ), + ), + ), + ); + + await tester.showKeyboard(find.byType(EditableText)); + final MethodCall setClient = log.first; + expect(setClient.method, 'TextInput.setClient'); + expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.light'); + }); } diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index a2110a0ef4..8331df37ee 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -1979,6 +1979,63 @@ testWidgets( )); expect(called, 2); }); + + testWidgets('default keyboardAppearance is resepcted', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/22212. + + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + + final TextEditingController controller = TextEditingController(); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: EditableText( + controller: controller, + focusNode: FocusNode(), + style: Typography(platform: TargetPlatform.android).black.subhead, + cursorColor: Colors.blue, + backgroundCursorColor: Colors.grey, + ), + ), + ); + + await tester.showKeyboard(find.byType(EditableText)); + final MethodCall setClient = log.first; + expect(setClient.method, 'TextInput.setClient'); + expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.light'); + }); + + testWidgets('custom keyboardAppearance is resepcted', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/22212. + + final List log = []; + SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + + final TextEditingController controller = TextEditingController(); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: EditableText( + controller: controller, + focusNode: FocusNode(), + style: Typography(platform: TargetPlatform.android).black.subhead, + cursorColor: Colors.blue, + backgroundCursorColor: Colors.grey, + keyboardAppearance: Brightness.dark, + ), + ), + ); + + await tester.showKeyboard(find.byType(EditableText)); + final MethodCall setClient = log.first; + expect(setClient.method, 'TextInput.setClient'); + expect(setClient.arguments.last['keyboardAppearance'], 'Brightness.dark'); + }); } class MockTextSelectionControls extends Mock implements TextSelectionControls {}