mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
dont mess with user supplied list (#69594)
This commit is contained in:
parent
88809aa247
commit
7d539043ba
@ -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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user