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
431b82fd
Unverified
Commit
431b82fd
authored
Sep 18, 2019
by
Justin McCandless
Committed by
GitHub
Sep 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TextField docs for getting value (#40695)
Added docs examples of getting the string from a TextField
parent
5aaac71f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
0 deletions
+120
-0
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+65
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+55
-0
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
431b82fd
...
...
@@ -188,6 +188,71 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
/// ```
/// {@end-tool}
///
/// ## Reading values
///
/// A common way to read a value from a TextField is to use the [onSubmitted]
/// callback. This callback is applied to the text field's current value when
/// the user finishes editing.
///
/// {@tool dartpad --template=stateful_widget_material}
///
/// This sample shows how to get a value from a TextField via the [onSubmitted]
/// callback.
///
/// ```dart
/// TextEditingController _controller;
///
/// void initState() {
/// super.initState();
/// _controller = TextEditingController();
/// }
///
/// void dispose() {
/// _controller.dispose();
/// super.dispose();
/// }
///
/// Widget build(BuildContext context) {
/// return Scaffold(
/// body: Center(
/// child: TextField(
/// controller: _controller,
/// onSubmitted: (String value) async {
/// await showDialog<void>(
/// context: context,
/// builder: (BuildContext context) {
/// return AlertDialog(
/// title: const Text('Thanks!'),
/// content: Text ('You typed "$value".'),
/// actions: <Widget>[
/// FlatButton(
/// onPressed: () { Navigator.pop(context); },
/// child: const Text('OK'),
/// ),
/// ],
/// );
/// },
/// );
/// },
/// ),
/// ),
/// );
/// }
/// ```
/// {@end-tool}
///
/// For most applications the [onSubmitted] callback will be sufficient for
/// reacting to user input.
///
/// The [onEditingComplete] callback also runs when the user finishes editing.
/// It's different from [onSubmitted] because it has a default value which
/// updates the text controller and yields the keyboard focus. Applications that
/// require different behavior can override the default [onEditingComplete]
/// callback.
///
/// Keep in mind you can also always read the current string from a TextField's
/// [TextEditingController] using [TextEditingController.text].
///
/// See also:
///
/// * <https://material.io/design/components/text-fields.html>
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
431b82fd
...
...
@@ -761,6 +761,61 @@ class EditableText extends StatefulWidget {
/// To be notified of all changes to the TextField's text, cursor,
/// and selection, one can add a listener to its [controller] with
/// [TextEditingController.addListener].
///
/// {@tool dartpad --template=stateful_widget_material}
///
/// This example shows how onChanged could be used to check the TextField's
/// current value each time the user inserts or deletes a character.
///
/// ```dart
/// TextEditingController _controller;
///
/// void initState() {
/// super.initState();
/// _controller = TextEditingController();
/// }
///
/// void dispose() {
/// _controller.dispose();
/// super.dispose();
/// }
///
/// Widget build(BuildContext context) {
/// return Scaffold(
/// body: Column(
/// mainAxisAlignment: MainAxisAlignment.center,
/// children: <Widget>[
/// const Text('What number comes next in the sequence?'),
/// const Text('1, 1, 2, 3, 5, 8...?'),
/// TextField(
/// controller: _controller,
/// onChanged: (String value) async {
/// if (value != '13') {
/// return;
/// }
/// await showDialog<void>(
/// context: context,
/// builder: (BuildContext context) {
/// return AlertDialog(
/// title: const Text('Thats correct!'),
/// content: Text ('13 is the right answer.'),
/// actions: <Widget>[
/// FlatButton(
/// onPressed: () { Navigator.pop(context); },
/// child: const Text('OK'),
/// ),
/// ],
/// );
/// },
/// );
/// },
/// ),
/// ],
/// ),
/// );
/// }
/// ```
/// {@end-tool}
/// {@endtemplate}
///
/// See also:
...
...
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