Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
63062a64
Unverified
Commit
63062a64
authored
Dec 13, 2020
by
Alex Li
Committed by
GitHub
Dec 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deprecate `maxLengthEnforced` for text fields (#72043)
parent
a76bb1a0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
6 deletions
+62
-6
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+16
-1
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+11
-1
text_form_field.dart
packages/flutter/lib/src/material/text_form_field.dart
+5
-0
text_formatter.dart
packages/flutter/lib/src/services/text_formatter.dart
+7
-4
text_formatter_test.dart
packages/flutter/test/services/text_formatter_test.dart
+23
-0
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
63062a64
...
...
@@ -262,6 +262,11 @@ class CupertinoTextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
...
...
@@ -409,6 +414,11 @@ class CupertinoTextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
...
...
@@ -654,6 +664,11 @@ class CupertinoTextField extends StatefulWidget {
///
/// If true, prevents the field from allowing more than [maxLength]
/// characters.
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
final
bool
maxLengthEnforced
;
/// Determines how the [maxLength] limit should be enforced.
...
...
@@ -808,7 +823,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
FocusNode
get
_effectiveFocusNode
=>
widget
.
focusNode
??
(
_focusNode
??=
FocusNode
());
MaxLengthEnforcement
get
_effectiveMaxLengthEnforcement
=>
widget
.
maxLengthEnforcement
??
LengthLimitingTextInputFormatter
.
inferredDefaultMaxLengthEnforcement
;
??
LengthLimitingTextInputFormatter
.
getDefaultMaxLengthEnforcement
()
;
bool
_showSelectionHandles
=
false
;
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
63062a64
...
...
@@ -359,6 +359,11 @@ class TextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
...
...
@@ -606,6 +611,11 @@ class TextField extends StatefulWidget {
///
/// If true, prevents the field from allowing more than [maxLength]
/// characters.
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
final
bool
maxLengthEnforced
;
/// Determines how the [maxLength] limit should be enforced.
...
...
@@ -856,7 +866,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
FocusNode
get
_effectiveFocusNode
=>
widget
.
focusNode
??
(
_focusNode
??=
FocusNode
());
MaxLengthEnforcement
get
_effectiveMaxLengthEnforcement
=>
widget
.
maxLengthEnforcement
??
LengthLimitingTextInputFormatter
.
inferredDefaultMaxLengthEnforcement
;
??
LengthLimitingTextInputFormatter
.
getDefaultMaxLengthEnforcement
(
Theme
.
of
(
context
).
platform
)
;
bool
_isHovering
=
false
;
...
...
packages/flutter/lib/src/material/text_form_field.dart
View file @
63062a64
...
...
@@ -165,6 +165,11 @@ class TextFormField extends FormField<String> {
'This feature was deprecated after v1.19.0.'
)
bool
autovalidate
=
false
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
)
bool
maxLengthEnforced
=
true
,
MaxLengthEnforcement
?
maxLengthEnforcement
,
int
?
maxLines
=
1
,
...
...
packages/flutter/lib/src/services/text_formatter.dart
View file @
63062a64
...
...
@@ -415,7 +415,8 @@ class LengthLimitingTextInputFormatter extends TextInputFormatter {
/// {@macro flutter.services.textFormatter.maxLengthEnforcement}
final
MaxLengthEnforcement
?
maxLengthEnforcement
;
/// Return an effective [MaxLengthEnforcement] according the target platform.
/// Returns a [MaxLengthEnforcement] that follows the specified [platform]'s
/// convention.
///
/// {@template flutter.services.textFormatter.effectiveMaxLengthEnforcement}
/// ### Platform specific behaviors
...
...
@@ -432,11 +433,13 @@ class LengthLimitingTextInputFormatter extends TextInputFormatter {
/// [MaxLengthEnforcement.truncateAfterCompositionEnds]. These platforms
/// allow the composition to exceed by default.
/// {@endtemplate}
static
MaxLengthEnforcement
get
inferredDefaultMaxLengthEnforcement
{
static
MaxLengthEnforcement
getDefaultMaxLengthEnforcement
([
TargetPlatform
?
platform
,
])
{
if
(
kIsWeb
)
{
return
MaxLengthEnforcement
.
truncateAfterCompositionEnds
;
}
else
{
switch
(
defaultTargetPlatform
)
{
switch
(
platform
??
defaultTargetPlatform
)
{
case
TargetPlatform
.
android
:
case
TargetPlatform
.
windows
:
return
MaxLengthEnforcement
.
enforced
;
...
...
@@ -493,7 +496,7 @@ class LengthLimitingTextInputFormatter extends TextInputFormatter {
assert
(
maxLength
>
0
);
switch
(
maxLengthEnforcement
??
inferredDefaultMaxLengthEnforcement
)
{
switch
(
maxLengthEnforcement
??
getDefaultMaxLengthEnforcement
()
)
{
case
MaxLengthEnforcement
.
none
:
return
newValue
;
case
MaxLengthEnforcement
.
enforced
:
...
...
packages/flutter/test/services/text_formatter_test.dart
View file @
63062a64
...
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -460,6 +461,28 @@ void main() {
expect
(
formatted
.
text
,
'bbbbbbbbbb'
);
});
});
group
(
'get enforcement from target platform'
,
()
{
// The enforcement on Web will be always `MaxLengthEnforcement.truncateAfterCompositionEnds`
test
(
'with TargetPlatform.windows'
,
()
async
{
final
MaxLengthEnforcement
enforcement
=
LengthLimitingTextInputFormatter
.
getDefaultMaxLengthEnforcement
(
TargetPlatform
.
windows
,
);
if
(
kIsWeb
)
{
expect
(
enforcement
,
MaxLengthEnforcement
.
truncateAfterCompositionEnds
);
}
else
{
expect
(
enforcement
,
MaxLengthEnforcement
.
enforced
);
}
});
test
(
'with TargetPlatform.macOS'
,
()
async
{
final
MaxLengthEnforcement
enforcement
=
LengthLimitingTextInputFormatter
.
getDefaultMaxLengthEnforcement
(
TargetPlatform
.
macOS
,
);
expect
(
enforcement
,
MaxLengthEnforcement
.
truncateAfterCompositionEnds
);
});
});
});
test
(
'FilteringTextInputFormatter should return the old value if new value contains non-white-listed character'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment