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
94dab8fe
Unverified
Commit
94dab8fe
authored
Nov 20, 2018
by
Hans Muller
Committed by
GitHub
Nov 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TextField.onTap() (#24536)
parent
9e0ce09f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
6 deletions
+107
-6
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+61
-1
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+46
-5
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
94dab8fe
...
...
@@ -127,6 +127,7 @@ class TextField extends StatefulWidget {
this
.
keyboardAppearance
,
this
.
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
this
.
enableInteractiveSelection
=
true
,
this
.
onTap
,
})
:
assert
(
textAlign
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
obscureText
!=
null
),
...
...
@@ -144,9 +145,44 @@ class TextField extends StatefulWidget {
/// If null, this widget will create its own [TextEditingController].
final
TextEditingController
controller
;
/// Controls whether this widget has keyboard focus.
/// Defines the keyboard focus for this widget.
///
/// The [focusNode] is a long-lived object that's typically managed by a
/// [StatefulWidget] parent. See [FocusNode] for more information.
///
/// To give the keyboard focus to this widget, provide a [focusNode] and then
/// use the current [FocusScope] to request the focus:
///
/// ```dart
/// FocusScope.of(context).requestFocus(myFocusNode);
/// ```
///
/// This happens automatically when the widget is tapped.
///
/// To be notified when the widget gains or loses the focus, add a listener
/// to the [focusNode]:
///
/// ```dart
/// focusNode.addListener(() { print(myFocusNode.hasFocus); });
/// ```
///
/// If null, this widget will create its own [FocusNode].
///
/// ## Keyboard
///
/// Requesting the focus will typically cause the the keyboard to be shown
/// if it's not showing already.
///
/// On Android, the user can hide the keyboard - withouth changing the focus -
/// with the system back button. They can restore the keyboard's visibility
/// by tapping on a text field. The user might hide the keyboard and
/// switch to a physical keyboard, or they might just need to get it
/// out of the way for a moment, to expose something it's
/// obscuring. In this case requesting the focus again will not
/// cause the focus to change, and will not make the keyboard visible.
///
/// This widget builds an [EditableText] and will ensure that the keyboard is
/// showing when it is tapped by calling [EditableTextState.requestKeyboard()].
final
FocusNode
focusNode
;
/// The decoration to show around the text field.
...
...
@@ -298,6 +334,26 @@ class TextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.enableInteractiveSelection}
final
bool
enableInteractiveSelection
;
/// Called when the user taps on this textfield.
///
/// The textfield builds a [GestureDetector] to handle input events like tap,
/// to trigger focus requests, to move the caret, adjust the selection, etc.
/// Handling some of those events by wrapping the textfield with a competing
/// GestureDetector is problematic.
///
/// To unconditionally handle taps, without interfering with the textfield's
/// internal gesture detector, provide this callback.
///
/// If the textfield is created with [enabled] false, taps will not be
/// recognized.
///
/// To be notified when the textfield gains or loses the focus, provide a
/// [focusNode] and add a listener to that.
///
/// To listen to arbitrary pointer events without competing with the
/// textfield's internal gesture detector, use a [Listener].
final
GestureTapCallback
onTap
;
@override
_TextFieldState
createState
()
=>
_TextFieldState
();
...
...
@@ -306,6 +362,7 @@ class TextField extends StatefulWidget {
super
.
debugFillProperties
(
properties
);
properties
.
add
(
DiagnosticsProperty
<
TextEditingController
>(
'controller'
,
controller
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
FocusNode
>(
'focusNode'
,
focusNode
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
bool
>(
'enabled'
,
enabled
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
InputDecoration
>(
'decoration'
,
decoration
));
properties
.
add
(
DiagnosticsProperty
<
TextInputType
>(
'keyboardType'
,
keyboardType
,
defaultValue:
TextInputType
.
text
));
properties
.
add
(
DiagnosticsProperty
<
TextStyle
>(
'style'
,
style
,
defaultValue:
null
));
...
...
@@ -315,6 +372,7 @@ class TextField extends StatefulWidget {
properties
.
add
(
IntProperty
(
'maxLines'
,
maxLines
,
defaultValue:
1
));
properties
.
add
(
IntProperty
(
'maxLength'
,
maxLength
,
defaultValue:
null
));
properties
.
add
(
FlagProperty
(
'maxLengthEnforced'
,
value:
maxLengthEnforced
,
ifTrue:
'max length enforced'
));
properties
.
add
(
DiagnosticsProperty
<
GestureTapCallback
>(
'onTap'
,
onTap
,
defaultValue:
false
));
}
}
...
...
@@ -453,6 +511,8 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
_renderEditable
.
handleTap
();
_requestKeyboard
();
_confirmCurrentSplash
();
if
(
widget
.
onTap
!=
null
)
widget
.
onTap
();
}
void
_handleTapCancel
()
{
...
...
packages/flutter/test/material/text_field_test.dart
View file @
94dab8fe
...
...
@@ -67,11 +67,13 @@ Widget overlay({ Widget child }) {
child:
Overlay
(
initialEntries:
<
OverlayEntry
>[
OverlayEntry
(
builder:
(
BuildContext
context
)
=>
Center
(
child:
Material
(
child:
child
,
),
),
builder:
(
BuildContext
context
)
{
return
Center
(
child:
Material
(
child:
child
,
),
);
},
),
],
),
...
...
@@ -3341,4 +3343,43 @@ void main() {
expect
(
minOffset
,
0.0
);
expect
(
maxOffset
,
50.0
);
});
testWidgets
(
'onTap is called upon tap'
,
(
WidgetTester
tester
)
async
{
int
tapCount
=
0
;
await
tester
.
pumpWidget
(
overlay
(
child:
TextField
(
onTap:
()
{
tapCount
+=
1
;
},
),
),
);
expect
(
tapCount
,
0
);
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
expect
(
tapCount
,
3
);
});
testWidgets
(
'onTap is not called, field is disabled'
,
(
WidgetTester
tester
)
async
{
int
tapCount
=
0
;
await
tester
.
pumpWidget
(
overlay
(
child:
TextField
(
enabled:
false
,
onTap:
()
{
tapCount
+=
1
;
},
),
),
);
expect
(
tapCount
,
0
);
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
expect
(
tapCount
,
0
);
});
}
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