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
326cd5e8
Unverified
Commit
326cd5e8
authored
Jun 25, 2019
by
LongCatIsLooong
Committed by
GitHub
Jun 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CupertinoTextField.onTap (#34964)
parent
f83fd9d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
1 deletion
+94
-1
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+7
-0
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+3
-1
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+84
-0
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
326cd5e8
...
@@ -196,6 +196,7 @@ class CupertinoTextField extends StatefulWidget {
...
@@ -196,6 +196,7 @@ class CupertinoTextField extends StatefulWidget {
this
.
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
this
.
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
enableInteractiveSelection
,
this
.
enableInteractiveSelection
,
this
.
onTap
,
this
.
scrollController
,
this
.
scrollController
,
this
.
scrollPhysics
,
this
.
scrollPhysics
,
})
:
assert
(
textAlign
!=
null
),
})
:
assert
(
textAlign
!=
null
),
...
@@ -458,6 +459,9 @@ class CupertinoTextField extends StatefulWidget {
...
@@ -458,6 +459,9 @@ class CupertinoTextField extends StatefulWidget {
return
enableInteractiveSelection
??
!
obscureText
;
return
enableInteractiveSelection
??
!
obscureText
;
}
}
/// {@macro flutter.material.textfield.onTap}
final
GestureTapCallback
onTap
;
@override
@override
_CupertinoTextFieldState
createState
()
=>
_CupertinoTextFieldState
();
_CupertinoTextFieldState
createState
()
=>
_CupertinoTextFieldState
();
...
@@ -584,6 +588,9 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
...
@@ -584,6 +588,9 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
_renderEditable
.
selectWordEdge
(
cause:
SelectionChangedCause
.
tap
);
_renderEditable
.
selectWordEdge
(
cause:
SelectionChangedCause
.
tap
);
}
}
_requestKeyboard
();
_requestKeyboard
();
if
(
widget
.
onTap
!=
null
)
{
widget
.
onTap
();
}
}
}
void
_handleSingleLongTapStart
(
LongPressStartDetails
details
)
{
void
_handleSingleLongTapStart
(
LongPressStartDetails
details
)
{
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
326cd5e8
...
@@ -432,7 +432,8 @@ class TextField extends StatefulWidget {
...
@@ -432,7 +432,8 @@ class TextField extends StatefulWidget {
return
enableInteractiveSelection
??
!
obscureText
;
return
enableInteractiveSelection
??
!
obscureText
;
}
}
/// Called when the user taps on this text field.
/// {@template flutter.material.textfield.onTap}
/// Called for each distinct tap except for every second tap of a double tap.
///
///
/// The text field builds a [GestureDetector] to handle input events like tap,
/// The text field builds a [GestureDetector] to handle input events like tap,
/// to trigger focus requests, to move the caret, adjust the selection, etc.
/// to trigger focus requests, to move the caret, adjust the selection, etc.
...
@@ -450,6 +451,7 @@ class TextField extends StatefulWidget {
...
@@ -450,6 +451,7 @@ class TextField extends StatefulWidget {
///
///
/// To listen to arbitrary pointer events without competing with the
/// To listen to arbitrary pointer events without competing with the
/// text field's internal gesture detector, use a [Listener].
/// text field's internal gesture detector, use a [Listener].
/// {@endtemplate}
final
GestureTapCallback
onTap
;
final
GestureTapCallback
onTap
;
/// Callback that generates a custom [InputDecorator.counter] widget.
/// Callback that generates a custom [InputDecorator.counter] widget.
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
326cd5e8
...
@@ -2512,6 +2512,90 @@ void main() {
...
@@ -2512,6 +2512,90 @@ void main() {
},
},
);
);
testWidgets
(
'onTap is called upon tap'
,
(
WidgetTester
tester
)
async
{
int
tapCount
=
0
;
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
onTap:
()
=>
tapCount
++,
),
),
),
);
expect
(
tapCount
,
0
);
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
await
tester
.
pump
();
expect
(
tapCount
,
1
);
// Wait out the double tap interval so the next tap doesn't end up being
// recognized as a double tap.
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Double tap count as one single tap.
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
await
tester
.
pump
();
expect
(
tapCount
,
2
);
});
testWidgets
(
'onTap does not work when the text field is disabled'
,
(
WidgetTester
tester
)
async
{
int
tapCount
=
0
;
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
enabled:
false
,
onTap:
()
=>
tapCount
++,
),
),
),
);
expect
(
tapCount
,
0
);
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
await
tester
.
pump
();
expect
(
tapCount
,
0
);
// Wait out the double tap interval so the next tap doesn't end up being
// recognized as a double tap.
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Enabling the text field, now it should accept taps.
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
onTap:
()
=>
tapCount
++,
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
expect
(
tapCount
,
1
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Disable it again.
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
enabled:
false
,
onTap:
()
=>
tapCount
++,
),
),
),
);
await
tester
.
tap
(
find
.
byType
(
CupertinoTextField
));
await
tester
.
pump
();
expect
(
tapCount
,
1
);
});
testWidgets
(
testWidgets
(
'text field respects theme'
,
'text field respects theme'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
...
...
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