Unverified Commit 45a70efa authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Respect EditableText.keyboardAppearance (#26721)

parent 60e9c585
......@@ -605,7 +605,9 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> 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<CupertinoTextField> with AutomaticK
cursorColor: widget.cursorColor,
backgroundCursorColor: CupertinoColors.inactiveGray,
scrollPadding: widget.scrollPadding,
keyboardAppearance: widget.keyboardAppearance,
keyboardAppearance: keyboardAppearance,
),
),
);
......
......@@ -798,6 +798,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
: TextInputAction.done
),
textCapitalization: widget.textCapitalization,
keyboardAppearance: widget.keyboardAppearance,
)
)..setEditingState(localValue);
}
......
......@@ -1168,4 +1168,52 @@ void main() {
);
},
);
testWidgets('text field respects keyboardAppearance from theme', (WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
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<MethodCall> log = <MethodCall>[];
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');
});
}
......@@ -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<MethodCall> log = <MethodCall>[];
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<MethodCall> log = <MethodCall>[];
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 {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment