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
71c374af
Commit
71c374af
authored
Jul 18, 2017
by
Jason Simmons
Committed by
GitHub
Jul 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a flag that controls autocorrect on text fields (#11180)
See
https://github.com/flutter/flutter/issues/11168
parent
898c19d7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
4 deletions
+41
-4
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+12
-1
text_form_field.dart
packages/flutter/lib/src/material/text_form_field.dart
+3
-0
text_input.dart
packages/flutter/lib/src/services/text_input.dart
+10
-2
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+13
-1
text_input_test.dart
packages/flutter/test/services/text_input_test.dart
+3
-0
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
71c374af
...
@@ -68,7 +68,8 @@ class TextField extends StatefulWidget {
...
@@ -68,7 +68,8 @@ class TextField extends StatefulWidget {
/// the number of lines. By default, it is 1, meaning this is a single-line
/// the number of lines. By default, it is 1, meaning this is a single-line
/// text field. If it is not null, it must be greater than zero.
/// text field. If it is not null, it must be greater than zero.
///
///
/// The [keyboardType], [autofocus], and [obscureText] arguments must not be null.
/// The [keyboardType], [autofocus], [obscureText], and [autocorrect] arguments
/// must not be null.
const
TextField
({
const
TextField
({
Key
key
,
Key
key
,
this
.
controller
,
this
.
controller
,
...
@@ -79,6 +80,7 @@ class TextField extends StatefulWidget {
...
@@ -79,6 +80,7 @@ class TextField extends StatefulWidget {
this
.
textAlign
,
this
.
textAlign
,
this
.
autofocus
:
false
,
this
.
autofocus
:
false
,
this
.
obscureText
:
false
,
this
.
obscureText
:
false
,
this
.
autocorrect
:
true
,
this
.
maxLines
:
1
,
this
.
maxLines
:
1
,
this
.
onChanged
,
this
.
onChanged
,
this
.
onSubmitted
,
this
.
onSubmitted
,
...
@@ -86,6 +88,7 @@ class TextField extends StatefulWidget {
...
@@ -86,6 +88,7 @@ class TextField extends StatefulWidget {
})
:
assert
(
keyboardType
!=
null
),
})
:
assert
(
keyboardType
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
super
(
key:
key
);
super
(
key:
key
);
...
@@ -142,6 +145,11 @@ class TextField extends StatefulWidget {
...
@@ -142,6 +145,11 @@ class TextField extends StatefulWidget {
/// Defaults to false. Cannot be null.
/// Defaults to false. Cannot be null.
final
bool
obscureText
;
final
bool
obscureText
;
/// Whether to enable autocorrection.
///
/// Defaults to true. Cannot be null.
final
bool
autocorrect
;
/// The maximum number of lines for the text to span, wrapping if necessary.
/// The maximum number of lines for the text to span, wrapping if necessary.
///
///
/// If this is 1 (the default), the text will not wrap, but will scroll
/// If this is 1 (the default), the text will not wrap, but will scroll
...
@@ -181,6 +189,8 @@ class TextField extends StatefulWidget {
...
@@ -181,6 +189,8 @@ class TextField extends StatefulWidget {
description
.
add
(
'autofocus:
$autofocus
'
);
description
.
add
(
'autofocus:
$autofocus
'
);
if
(
obscureText
)
if
(
obscureText
)
description
.
add
(
'obscureText:
$obscureText
'
);
description
.
add
(
'obscureText:
$obscureText
'
);
if
(
autocorrect
)
description
.
add
(
'autocorrect:
$autocorrect
'
);
if
(
maxLines
!=
1
)
if
(
maxLines
!=
1
)
description
.
add
(
'maxLines:
$maxLines
'
);
description
.
add
(
'maxLines:
$maxLines
'
);
}
}
...
@@ -243,6 +253,7 @@ class _TextFieldState extends State<TextField> {
...
@@ -243,6 +253,7 @@ class _TextFieldState extends State<TextField> {
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
autofocus:
widget
.
autofocus
,
autofocus:
widget
.
autofocus
,
obscureText:
widget
.
obscureText
,
obscureText:
widget
.
obscureText
,
autocorrect:
widget
.
autocorrect
,
maxLines:
widget
.
maxLines
,
maxLines:
widget
.
maxLines
,
cursorColor:
themeData
.
textSelectionColor
,
cursorColor:
themeData
.
textSelectionColor
,
selectionColor:
themeData
.
textSelectionColor
,
selectionColor:
themeData
.
textSelectionColor
,
...
...
packages/flutter/lib/src/material/text_form_field.dart
View file @
71c374af
...
@@ -41,6 +41,7 @@ class TextFormField extends FormField<String> {
...
@@ -41,6 +41,7 @@ class TextFormField extends FormField<String> {
TextStyle
style
,
TextStyle
style
,
bool
autofocus:
false
,
bool
autofocus:
false
,
bool
obscureText:
false
,
bool
obscureText:
false
,
bool
autocorrect:
true
,
int
maxLines:
1
,
int
maxLines:
1
,
FormFieldSetter
<
String
>
onSaved
,
FormFieldSetter
<
String
>
onSaved
,
FormFieldValidator
<
String
>
validator
,
FormFieldValidator
<
String
>
validator
,
...
@@ -48,6 +49,7 @@ class TextFormField extends FormField<String> {
...
@@ -48,6 +49,7 @@ class TextFormField extends FormField<String> {
})
:
assert
(
keyboardType
!=
null
),
})
:
assert
(
keyboardType
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
super
(
super
(
key:
key
,
key:
key
,
...
@@ -63,6 +65,7 @@ class TextFormField extends FormField<String> {
...
@@ -63,6 +65,7 @@ class TextFormField extends FormField<String> {
style:
style
,
style:
style
,
autofocus:
autofocus
,
autofocus:
autofocus
,
obscureText:
obscureText
,
obscureText:
obscureText
,
autocorrect:
autocorrect
,
maxLines:
maxLines
,
maxLines:
maxLines
,
onChanged:
field
.
onChanged
,
onChanged:
field
.
onChanged
,
inputFormatters:
inputFormatters
,
inputFormatters:
inputFormatters
,
...
...
packages/flutter/lib/src/services/text_input.dart
View file @
71c374af
...
@@ -67,13 +67,15 @@ enum TextInputAction {
...
@@ -67,13 +67,15 @@ enum TextInputAction {
class
TextInputConfiguration
{
class
TextInputConfiguration
{
/// Creates configuration information for a text input control.
/// Creates configuration information for a text input control.
///
///
/// The [inputType]
and [obscureTex
t] arguments must not be null.
/// The [inputType]
, [obscureText], and [autocorrec
t] arguments must not be null.
const
TextInputConfiguration
({
const
TextInputConfiguration
({
this
.
inputType
:
TextInputType
.
text
,
this
.
inputType
:
TextInputType
.
text
,
this
.
obscureText
:
false
,
this
.
obscureText
:
false
,
this
.
autocorrect
:
true
,
this
.
actionLabel
,
this
.
actionLabel
,
})
:
assert
(
inputType
!=
null
),
})
:
assert
(
inputType
!=
null
),
assert
(
obscureText
!=
null
);
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
);
/// The type of information for which to optimize the text input control.
/// The type of information for which to optimize the text input control.
final
TextInputType
inputType
;
final
TextInputType
inputType
;
...
@@ -83,6 +85,11 @@ class TextInputConfiguration {
...
@@ -83,6 +85,11 @@ class TextInputConfiguration {
/// Defaults to false.
/// Defaults to false.
final
bool
obscureText
;
final
bool
obscureText
;
/// Whether to enable autocorrection.
///
/// Defaults to true.
final
bool
autocorrect
;
/// What text to display in the text input control's action button.
/// What text to display in the text input control's action button.
final
String
actionLabel
;
final
String
actionLabel
;
...
@@ -91,6 +98,7 @@ class TextInputConfiguration {
...
@@ -91,6 +98,7 @@ class TextInputConfiguration {
return
<
String
,
dynamic
>{
return
<
String
,
dynamic
>{
'inputType'
:
inputType
.
toString
(),
'inputType'
:
inputType
.
toString
(),
'obscureText'
:
obscureText
,
'obscureText'
:
obscureText
,
'autocorrect'
:
autocorrect
,
'actionLabel'
:
actionLabel
,
'actionLabel'
:
actionLabel
,
};
};
}
}
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
71c374af
...
@@ -147,6 +147,7 @@ class EditableText extends StatefulWidget {
...
@@ -147,6 +147,7 @@ class EditableText extends StatefulWidget {
@required
this
.
controller
,
@required
this
.
controller
,
@required
this
.
focusNode
,
@required
this
.
focusNode
,
this
.
obscureText
:
false
,
this
.
obscureText
:
false
,
this
.
autocorrect
:
true
,
@required
this
.
style
,
@required
this
.
style
,
@required
this
.
cursorColor
,
@required
this
.
cursorColor
,
this
.
textAlign
,
this
.
textAlign
,
...
@@ -163,6 +164,7 @@ class EditableText extends StatefulWidget {
...
@@ -163,6 +164,7 @@ class EditableText extends StatefulWidget {
})
:
assert
(
controller
!=
null
),
})
:
assert
(
controller
!=
null
),
assert
(
focusNode
!=
null
),
assert
(
focusNode
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
),
assert
(
style
!=
null
),
assert
(
style
!=
null
),
assert
(
cursorColor
!=
null
),
assert
(
cursorColor
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
...
@@ -186,6 +188,11 @@ class EditableText extends StatefulWidget {
...
@@ -186,6 +188,11 @@ class EditableText extends StatefulWidget {
/// Defaults to false.
/// Defaults to false.
final
bool
obscureText
;
final
bool
obscureText
;
/// Whether to enable autocorrection.
///
/// Defaults to true.
final
bool
autocorrect
;
/// The text style to use for the editable text.
/// The text style to use for the editable text.
final
TextStyle
style
;
final
TextStyle
style
;
...
@@ -253,6 +260,8 @@ class EditableText extends StatefulWidget {
...
@@ -253,6 +260,8 @@ class EditableText extends StatefulWidget {
description
.
add
(
'focusNode:
$focusNode
'
);
description
.
add
(
'focusNode:
$focusNode
'
);
if
(
obscureText
!=
false
)
if
(
obscureText
!=
false
)
description
.
add
(
'obscureText:
$obscureText
'
);
description
.
add
(
'obscureText:
$obscureText
'
);
if
(
autocorrect
!=
true
)
description
.
add
(
'autocorrect:
$autocorrect
'
);
description
.
add
(
'
${style.toString().split("\n").join(", ")}
'
);
description
.
add
(
'
${style.toString().split("\n").join(", ")}
'
);
if
(
textAlign
!=
null
)
if
(
textAlign
!=
null
)
description
.
add
(
'
$textAlign
'
);
description
.
add
(
'
$textAlign
'
);
...
@@ -388,7 +397,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -388,7 +397,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(!
_hasInputConnection
)
{
if
(!
_hasInputConnection
)
{
final
TextEditingValue
localValue
=
_value
;
final
TextEditingValue
localValue
=
_value
;
_lastKnownRemoteTextEditingValue
=
localValue
;
_lastKnownRemoteTextEditingValue
=
localValue
;
_textInputConnection
=
TextInput
.
attach
(
this
,
new
TextInputConfiguration
(
inputType:
widget
.
keyboardType
,
obscureText:
widget
.
obscureText
))
_textInputConnection
=
TextInput
.
attach
(
this
,
new
TextInputConfiguration
(
inputType:
widget
.
keyboardType
,
obscureText:
widget
.
obscureText
,
autocorrect:
widget
.
autocorrect
))
..
setEditingState
(
localValue
);
..
setEditingState
(
localValue
);
}
}
_textInputConnection
.
show
();
_textInputConnection
.
show
();
...
@@ -578,6 +587,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -578,6 +587,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
textScaleFactor:
widget
.
textScaleFactor
??
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
,
textScaleFactor:
widget
.
textScaleFactor
??
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
,
textAlign:
widget
.
textAlign
,
textAlign:
widget
.
textAlign
,
obscureText:
widget
.
obscureText
,
obscureText:
widget
.
obscureText
,
autocorrect:
widget
.
autocorrect
,
offset:
offset
,
offset:
offset
,
onSelectionChanged:
_handleSelectionChanged
,
onSelectionChanged:
_handleSelectionChanged
,
onCaretChanged:
_handleCaretChanged
,
onCaretChanged:
_handleCaretChanged
,
...
@@ -600,6 +610,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -600,6 +610,7 @@ class _Editable extends LeafRenderObjectWidget {
this
.
textScaleFactor
,
this
.
textScaleFactor
,
this
.
textAlign
,
this
.
textAlign
,
this
.
obscureText
,
this
.
obscureText
,
this
.
autocorrect
,
this
.
offset
,
this
.
offset
,
this
.
onSelectionChanged
,
this
.
onSelectionChanged
,
this
.
onCaretChanged
,
this
.
onCaretChanged
,
...
@@ -614,6 +625,7 @@ class _Editable extends LeafRenderObjectWidget {
...
@@ -614,6 +625,7 @@ class _Editable extends LeafRenderObjectWidget {
final
double
textScaleFactor
;
final
double
textScaleFactor
;
final
TextAlign
textAlign
;
final
TextAlign
textAlign
;
final
bool
obscureText
;
final
bool
obscureText
;
final
bool
autocorrect
;
final
ViewportOffset
offset
;
final
ViewportOffset
offset
;
final
SelectionChangedHandler
onSelectionChanged
;
final
SelectionChangedHandler
onSelectionChanged
;
final
CaretChangedHandler
onCaretChanged
;
final
CaretChangedHandler
onCaretChanged
;
...
...
packages/flutter/test/services/text_input_test.dart
View file @
71c374af
...
@@ -11,6 +11,7 @@ void main() {
...
@@ -11,6 +11,7 @@ void main() {
final
TextInputConfiguration
configuration
=
const
TextInputConfiguration
();
final
TextInputConfiguration
configuration
=
const
TextInputConfiguration
();
expect
(
configuration
.
inputType
,
TextInputType
.
text
);
expect
(
configuration
.
inputType
,
TextInputType
.
text
);
expect
(
configuration
.
obscureText
,
false
);
expect
(
configuration
.
obscureText
,
false
);
expect
(
configuration
.
autocorrect
,
true
);
expect
(
configuration
.
actionLabel
,
null
);
expect
(
configuration
.
actionLabel
,
null
);
});
});
...
@@ -18,11 +19,13 @@ void main() {
...
@@ -18,11 +19,13 @@ void main() {
final
TextInputConfiguration
configuration
=
const
TextInputConfiguration
(
final
TextInputConfiguration
configuration
=
const
TextInputConfiguration
(
inputType:
TextInputType
.
number
,
inputType:
TextInputType
.
number
,
obscureText:
true
,
obscureText:
true
,
autocorrect:
false
,
actionLabel:
'xyzzy'
actionLabel:
'xyzzy'
);
);
final
Map
<
String
,
dynamic
>
json
=
configuration
.
toJSON
();
final
Map
<
String
,
dynamic
>
json
=
configuration
.
toJSON
();
expect
(
json
[
'inputType'
],
'TextInputType.number'
);
expect
(
json
[
'inputType'
],
'TextInputType.number'
);
expect
(
json
[
'obscureText'
],
true
);
expect
(
json
[
'obscureText'
],
true
);
expect
(
json
[
'autocorrect'
],
false
);
expect
(
json
[
'actionLabel'
],
'xyzzy'
);
expect
(
json
[
'actionLabel'
],
'xyzzy'
);
});
});
});
});
...
...
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