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
5c6f65ee
Unverified
Commit
5c6f65ee
authored
May 20, 2022
by
Bruno Leroux
Committed by
GitHub
May 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Tooltip onTriggered callback (#104237)
Co-authored-by:
Bruno Leroux
<
bruno.leroux@gmail.com
>
parent
4e4da19c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
1 deletion
+62
-1
tooltip.dart
packages/flutter/lib/src/material/tooltip.dart
+11
-0
tooltip_test.dart
packages/flutter/test/material/tooltip_test.dart
+51
-1
No files found.
packages/flutter/lib/src/material/tooltip.dart
View file @
5c6f65ee
...
...
@@ -16,6 +16,9 @@ import 'theme.dart';
import
'tooltip_theme.dart'
;
import
'tooltip_visibility.dart'
;
/// Signature for when a tooltip is triggered.
typedef
TooltipTriggeredCallback
=
void
Function
();
/// A Material Design tooltip.
///
/// Tooltips provide text labels which help explain the function of a button or
...
...
@@ -108,6 +111,7 @@ class Tooltip extends StatefulWidget {
this
.
showDuration
,
this
.
triggerMode
,
this
.
enableFeedback
,
this
.
onTriggered
,
this
.
child
,
})
:
assert
((
message
==
null
)
!=
(
richMessage
==
null
),
'Either `message` or `richMessage` must be specified'
),
assert
(
...
...
@@ -238,6 +242,12 @@ class Tooltip extends StatefulWidget {
/// * [Feedback], for providing platform-specific feedback to certain actions.
final
bool
?
enableFeedback
;
/// Called when the Tooltip is triggered.
///
/// The tooltip is triggered after a tap when [triggerMode] is [TooltipTriggerMode.tap]
/// or after a long press when [triggerMode] is [TooltipTriggerMode.longPress].
final
TooltipTriggeredCallback
?
onTriggered
;
static
final
List
<
TooltipState
>
_openedTooltips
=
<
TooltipState
>[];
// Causes any current tooltips to be concealed. Only called for mouse hover enter
...
...
@@ -661,6 +671,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
else
Feedback
.
forTap
(
context
);
}
widget
.
onTriggered
?.
call
();
}
@override
...
...
packages/flutter/test/material/tooltip_test.dart
View file @
5c6f65ee
...
...
@@ -1764,6 +1764,55 @@ void main() {
expect
(
find
.
text
(
tooltipText
),
findsNothing
);
});
testWidgets
(
'Tooltip onTriggered is called when Tooltip triggers'
,
(
WidgetTester
tester
)
async
{
bool
onTriggeredCalled
=
false
;
void
onTriggered
()
=>
onTriggeredCalled
=
true
;
await
setWidgetForTooltipMode
(
tester
,
TooltipTriggerMode
.
longPress
,
onTriggered:
onTriggered
);
Finder
tooltip
=
find
.
byType
(
Tooltip
);
await
testGestureLongPress
(
tester
,
tooltip
);
expect
(
onTriggeredCalled
,
true
);
onTriggeredCalled
=
false
;
await
setWidgetForTooltipMode
(
tester
,
TooltipTriggerMode
.
tap
,
onTriggered:
onTriggered
);
tooltip
=
find
.
byType
(
Tooltip
);
await
testGestureTap
(
tester
,
tooltip
);
expect
(
onTriggeredCalled
,
true
);
});
testWidgets
(
'Tooltip onTriggered is not called when Tooltip is hovered'
,
(
WidgetTester
tester
)
async
{
bool
onTriggeredCalled
=
false
;
void
onTriggered
()
=>
onTriggeredCalled
=
true
;
const
Duration
waitDuration
=
Duration
.
zero
;
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
);
await
gesture
.
addPointer
();
await
gesture
.
moveTo
(
Offset
.
zero
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Center
(
child:
Tooltip
(
message:
tooltipText
,
waitDuration:
waitDuration
,
onTriggered:
onTriggered
,
child:
const
SizedBox
(
width:
100.0
,
height:
100.0
,
),
),
),
),
);
final
Finder
tooltip
=
find
.
byType
(
Tooltip
);
await
gesture
.
moveTo
(
tester
.
getCenter
(
tooltip
));
await
tester
.
pump
();
// Wait for it to appear.
await
tester
.
pump
(
waitDuration
);
expect
(
onTriggeredCalled
,
false
);
});
testWidgets
(
'Tooltip should not be shown with empty message (with child)'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
...
...
@@ -1791,12 +1840,13 @@ void main() {
});
}
Future
<
void
>
setWidgetForTooltipMode
(
WidgetTester
tester
,
TooltipTriggerMode
triggerMode
)
async
{
Future
<
void
>
setWidgetForTooltipMode
(
WidgetTester
tester
,
TooltipTriggerMode
triggerMode
,
{
TooltipTriggeredCallback
?
onTriggered
}
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Tooltip
(
message:
tooltipText
,
triggerMode:
triggerMode
,
onTriggered:
onTriggered
,
child:
const
SizedBox
(
width:
100.0
,
height:
100.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