Unverified Commit f1e87c48 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Clarify showDuration and waitDuration API docs and test behavior (#36970)

* Improve showDuration and waitDuration explanation and tests

* Add condition to test to ensure that tooltip does not show before long press duration is over
parent 07683f1d
...@@ -124,10 +124,14 @@ class Tooltip extends StatefulWidget { ...@@ -124,10 +124,14 @@ class Tooltip extends StatefulWidget {
/// The length of time that a pointer must hover over a tooltip's widget /// The length of time that a pointer must hover over a tooltip's widget
/// before the tooltip will be shown. /// before the tooltip will be shown.
/// ///
/// Once the pointer leaves the widget, the tooltip will immediately
/// disappear.
///
/// Defaults to 0 milliseconds (tooltips are shown immediately upon hover). /// Defaults to 0 milliseconds (tooltips are shown immediately upon hover).
final Duration waitDuration; final Duration waitDuration;
/// The length of time that the tooltip will be shown once it has appeared. /// The length of time that the tooltip will be shown after a long press
/// is released.
/// ///
/// Defaults to 1.5 seconds. /// Defaults to 1.5 seconds.
final Duration showDuration; final Duration showDuration;
...@@ -220,7 +224,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -220,7 +224,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
return; return;
} }
if (_longPressActivated) { if (_longPressActivated) {
// Tool tips activated by long press should stay around for 1.5s. // Tool tips activated by long press should stay around for the showDuration.
_hideTimer ??= Timer(showDuration, _controller.reverse); _hideTimer ??= Timer(showDuration, _controller.reverse);
} else { } else {
// Tool tips activated by hover should disappear as soon as the mouse // Tool tips activated by hover should disappear as soon as the mouse
......
...@@ -574,7 +574,7 @@ void main() { ...@@ -574,7 +574,7 @@ void main() {
)); ));
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('Tooltip stays around', (WidgetTester tester) async { testWidgets('Tooltip stays after long press', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Center( home: Center(
...@@ -592,18 +592,30 @@ void main() { ...@@ -592,18 +592,30 @@ void main() {
final Finder tooltip = find.byType(Tooltip); final Finder tooltip = find.byType(Tooltip);
TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip)); TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip));
// long press reveals tooltip
await tester.pump(kLongPressTimeout); await tester.pump(kLongPressTimeout);
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
await gesture.up();
expect(find.text(tooltipText), findsOneWidget); expect(find.text(tooltipText), findsOneWidget);
await gesture.up();
// tap (down, up) gesture hides tooltip, since its not
// a long press
await tester.tap(tooltip); await tester.tap(tooltip);
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
expect(find.text(tooltipText), findsNothing);
// long press once more
gesture = await tester.startGesture(tester.getCenter(tooltip)); gesture = await tester.startGesture(tester.getCenter(tooltip));
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 300)); await tester.pump(const Duration(milliseconds: 300));
expect(find.text(tooltipText), findsNothing); expect(find.text(tooltipText), findsNothing);
await tester.pump(kLongPressTimeout); await tester.pump(kLongPressTimeout);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text(tooltipText), findsOneWidget); expect(find.text(tooltipText), findsOneWidget);
// keep holding the long press, should still show tooltip
await tester.pump(kLongPressTimeout); await tester.pump(kLongPressTimeout);
expect(find.text(tooltipText), findsOneWidget); expect(find.text(tooltipText), findsOneWidget);
gesture.up(); gesture.up();
...@@ -611,7 +623,6 @@ void main() { ...@@ -611,7 +623,6 @@ void main() {
testWidgets('Tooltip shows/hides when hovered', (WidgetTester tester) async { testWidgets('Tooltip shows/hides when hovered', (WidgetTester tester) async {
const Duration waitDuration = Duration(milliseconds: 0); const Duration waitDuration = Duration(milliseconds: 0);
const Duration showDuration = Duration(milliseconds: 1500);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await gesture.addPointer(); await gesture.addPointer();
await gesture.moveTo(const Offset(1.0, 1.0)); await gesture.moveTo(const Offset(1.0, 1.0));
...@@ -623,7 +634,6 @@ void main() { ...@@ -623,7 +634,6 @@ void main() {
home: Center( home: Center(
child: Tooltip( child: Tooltip(
message: tooltipText, message: tooltipText,
showDuration: showDuration,
waitDuration: waitDuration, waitDuration: waitDuration,
child: Container( child: Container(
width: 100.0, width: 100.0,
...@@ -653,7 +663,6 @@ void main() { ...@@ -653,7 +663,6 @@ void main() {
await tester.pump(); await tester.pump();
// Wait for it to disappear. // Wait for it to disappear.
await tester.pump(showDuration);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await gesture.removePointer(); await gesture.removePointer();
expect(find.text(tooltipText), findsNothing); expect(find.text(tooltipText), findsNothing);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment