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
f6da3b2a
Commit
f6da3b2a
authored
Sep 27, 2016
by
Matt Perry
Committed by
GitHub
Sep 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a Submit button to text fields demo. (#6102)
Fixes
https://github.com/flutter/flutter/issues/6056
parent
a426b6b3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
text_field_demo.dart
examples/flutter_gallery/lib/demo/text_field_demo.dart
+19
-5
input.dart
packages/flutter/lib/src/material/input.dart
+2
-1
No files found.
examples/flutter_gallery/lib/demo/text_field_demo.dart
View file @
f6da3b2a
...
...
@@ -14,9 +14,9 @@ class TextFieldDemo extends StatefulWidget {
}
class
PersonData
{
String
name
;
String
phoneNumber
;
String
password
;
String
name
=
''
;
String
phoneNumber
=
''
;
String
password
=
''
;
}
class
TextFieldDemoState
extends
State
<
TextFieldDemo
>
{
...
...
@@ -31,8 +31,15 @@ class TextFieldDemoState extends State<TextFieldDemo> {
}
void
_handleSubmitted
()
{
// TODO(mpcomplete): Form could keep track of validation errors?
if
(
_validateName
(
person
.
name
)
!=
null
||
_validatePhoneNumber
(
person
.
phoneNumber
)
!=
null
||
_validatePassword
(
person
.
password
)
!=
null
)
{
showInSnackBar
(
'Please fix the errors in red before submitting.'
);
}
else
{
showInSnackBar
(
'
${person.name}
\'
s phone number is
${person.phoneNumber}
'
);
}
}
String
_validateName
(
String
value
)
{
if
(
value
.
isEmpty
)
...
...
@@ -66,7 +73,6 @@ class TextFieldDemoState extends State<TextFieldDemo> {
title:
new
Text
(
'Text fields'
)
),
body:
new
Form
(
onSubmitted:
_handleSubmitted
,
child:
new
Block
(
padding:
const
EdgeInsets
.
all
(
8.0
),
children:
<
Widget
>[
...
...
@@ -112,6 +118,14 @@ class TextFieldDemoState extends State<TextFieldDemo> {
)
)
]
),
new
Container
(
padding:
const
EdgeInsets
.
all
(
20.0
),
align:
const
FractionalOffset
(
0.5
,
0.5
),
child:
new
RaisedButton
(
child:
new
Text
(
'SUBMIT'
),
onPressed:
_handleSubmitted
,
),
)
]
)
...
...
packages/flutter/lib/src/material/input.dart
View file @
f6da3b2a
...
...
@@ -290,6 +290,7 @@ class _FormFieldData {
void
onSubmitted
(
InputValue
value
)
{
FormScope
scope
=
FormScope
.
of
(
inputState
.
context
);
assert
(
scope
!=
null
);
if
(
scope
.
form
.
onSubmitted
!=
null
)
scope
.
form
.
onSubmitted
();
scope
.
onFieldChanged
();
}
...
...
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