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
9f35f6c3
Unverified
Commit
9f35f6c3
authored
Feb 28, 2019
by
Hans Muller
Committed by
GitHub
Feb 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add warnings and an example to the TextEditingController docs (#28604)
parent
6ed9da35
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
3 deletions
+59
-3
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+59
-3
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
9f35f6c3
...
...
@@ -62,6 +62,50 @@ const int _kObscureShowLatestCharCursorTicks = 3;
/// text field. If you build a text field with a controller that already has
/// [text], the text field will use that text as its initial value.
///
/// The [text] or [selection] properties can be set from within a listener
/// added to this controller. If both properties need to be changed then the
/// controller's [value] should be set instead.
///
/// {@tool snippet --template=stateful_widget_material}
/// This example creates a [TextField] with a [TextEditingController] whose
/// change listener forces the entered text to be lower case and keeps the
/// cursor at the end of the input.
///
/// ```dart
/// final _controller = TextEditingController();
///
/// void initState() {
/// _controller.addListener(() {
/// final text = _controller.text.toLowerCase();
/// _controller.value = _controller.value.copyWith(
/// text: text,
/// selection: TextSelection(baseOffset: text.length, extentOffset: text.length),
/// composing: TextRange.empty,
/// );
/// });
/// super.initState();
/// }
///
/// void dispose() {
/// _controller.dispose();
/// super.dispose();
/// }
///
/// Widget build(BuildContext context) {
/// return Scaffold(
/// body: Container(
/// alignment: Alignment.center,
/// padding: const EdgeInsets.all(6),
/// child: TextFormField(
/// controller: _controller,
/// decoration: InputDecoration(border: OutlineInputBorder()),
/// ),
/// ),
/// );
/// }
/// ```
/// {@end-tool}
///
/// See also:
///
/// * [TextField], which is a Material Design text field that can be controlled
...
...
@@ -89,10 +133,17 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
/// that they need to update (it calls [notifyListeners]). For this reason,
/// this value should only be set between frames, e.g. in response to user
/// actions, not during the build, layout, or paint phases.
///
/// This property can be set from a listener added to this
/// [TextEditingController]; however, one should not also set [selection]
/// in a separate statement. To change both the [text] and the [selection]
/// change the controller's [value].
set
text
(
String
newText
)
{
value
=
value
.
copyWith
(
text:
newText
,
value
=
value
.
copyWith
(
text:
newText
,
selection:
const
TextSelection
.
collapsed
(
offset:
-
1
),
composing:
TextRange
.
empty
);
composing:
TextRange
.
empty
);
}
/// The currently selected [text].
...
...
@@ -104,6 +155,11 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
/// that they need to update (it calls [notifyListeners]). For this reason,
/// this value should only be set between frames, e.g. in response to user
/// actions, not during the build, layout, or paint phases.
///
/// This property can be set from a listener added to this
/// [TextEditingController]; however, one should not also set [text]
/// in a separate statement. To change both the [text] and the [selection]
/// change the controller's [value].
set
selection
(
TextSelection
newSelection
)
{
if
(
newSelection
.
start
>
text
.
length
||
newSelection
.
end
>
text
.
length
)
throw
FlutterError
(
'invalid text selection:
$newSelection
'
);
...
...
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