Unverified Commit 7d539043 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

dont mess with user supplied list (#69594)

parent 88809aa2
......@@ -878,13 +878,13 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
super.build(context); // See AutomaticKeepAliveClientMixin.
assert(debugCheckHasDirectionality(context));
final TextEditingController controller = _effectiveController;
final List<TextInputFormatter> formatters = widget.inputFormatters ?? <TextInputFormatter>[];
final TextSelectionControls textSelectionControls = widget.selectionControls ?? cupertinoTextSelectionControls;
final bool enabled = widget.enabled ?? true;
final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, 0);
if (widget.maxLength != null && widget.maxLengthEnforced) {
formatters.add(LengthLimitingTextInputFormatter(widget.maxLength));
}
final List<TextInputFormatter> formatters = <TextInputFormatter>[
...?widget.inputFormatters,
if (widget.maxLength != null && widget.maxLengthEnforced) LengthLimitingTextInputFormatter(widget.maxLength)
];
final CupertinoThemeData themeData = CupertinoTheme.of(context);
final TextStyle? resolvedStyle = widget.style?.copyWith(
......
......@@ -1261,9 +1261,10 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.primaryColorBrightness;
final TextEditingController controller = _effectiveController;
final FocusNode focusNode = _effectiveFocusNode;
final List<TextInputFormatter> formatters = widget.inputFormatters ?? <TextInputFormatter>[];
if (widget.maxLength != null && widget.maxLengthEnforced)
formatters.add(LengthLimitingTextInputFormatter(widget.maxLength));
final List<TextInputFormatter> formatters = <TextInputFormatter>[
...?widget.inputFormatters,
if (widget.maxLength != null && widget.maxLengthEnforced) LengthLimitingTextInputFormatter(widget.maxLength)
];
TextSelectionControls? textSelectionControls = widget.selectionControls;
final bool paintCursorAboveText;
......
......@@ -4289,4 +4289,16 @@ void main() {
final EditableText widget = tester.widget(find.byType(EditableText));
expect(widget.selectionControls, equals(selectionControl));
});
testWidgets('Do not add LengthLimiting formatter to the user supplied list', (WidgetTester tester) async {
final List<TextInputFormatter> formatters = <TextInputFormatter>[];
await tester.pumpWidget(
CupertinoApp(
home: CupertinoTextField(maxLength: 5, inputFormatters: formatters),
)
);
expect(formatters.isEmpty, isTrue);
});
}
......@@ -3344,6 +3344,22 @@ void main() {
expect(textController.text, '145623');
});
testWidgets('Do not add LengthLimiting formatter to the user supplied list', (WidgetTester tester) async {
final List<TextInputFormatter> formatters = <TextInputFormatter>[];
await tester.pumpWidget(
overlay(
child: TextField(
decoration: null,
maxLength: 5,
inputFormatters: formatters,
),
),
);
expect(formatters.isEmpty, isTrue);
});
testWidgets('Text field scrolls the caret into view', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();
......
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