flutter/examples/api/test/material/tooltip/tooltip.1_test.dart
Jasper van Riet 3c422dd750
Introduce exitDuration to Tooltip for mouse pointer devices (#138321)
This PR introduces a new property `exitDuration` to Tooltip, the counterpart to `waitDuration`. The need for this is shown by #136586. This changes the behaviour of `showDuration` on mouse pointer devices. This is because the use cases for the current behaviour on touch screen devices vs mouse pointer devices is fundamentally different.

<details>
<summary>Demo: tooltip with showDuration set</summary>

Tooltip disappears after 100 ms when moving away the mouse. Tooltip will not disappear when hovered.

https://github.com/flutter/flutter/assets/5138348/81d36dc9-78e0-4723-a84b-2552843ee181

</details>

Currently, when `showDuration` is set, this adjusts the time it takes for the tooltip to hide _after_ a mouse pointer has left the tooltip. This is not the same use case as its effect on touch screen devices, where it dictates how long the tooltip stays on screen after a long press. That is needed because the tooltip takes up screen space and there is not an intuitive way to hide it, whereas when using a mouse users expect to simply have to hover somewhere else. Having the tooltip stay around will look broken.

Thus, this PR splits the two use cases. `showDuration` no longer affects mouse pointer devices at all*. There is a precedent for such mouse pointer-only behaviour in `waitDuration`. Instead, I have split up the two use cases and created the new property `exitDuration`, which will still allow for tweaking the time it takes for the tooltip to hide after the user has moved their mouse pointer somewhere else.

*Note: Should `showDuration` affect [this line](e33d4b8627/packages/flutter/lib/src/material/tooltip.dart (L610))?

Fixes #136586.

Note: I noticed that when I made the change, no tests were broken. Hopefully, the tests added here help that in the future. I also noticed that in the _existing_ tests, the `waitDuration` tests contain assertions that implicate that it is the role of `waitDuration` to change this behaviour, but that's not currently (nor in the new behaviour) true, so I have fixed those tests.
2023-12-07 21:20:06 +00:00

45 lines
1.8 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/tooltip/tooltip.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tooltip wait and show duration', (WidgetTester tester) async {
const String tooltipText = 'I am a Tooltip';
await tester.pumpWidget(
const example.TooltipExampleApp(),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
addTearDown(() async {
return gesture.removePointer();
});
await gesture.addPointer();
await gesture.moveTo(const Offset(1.0, 1.0));
await tester.pump();
expect(find.text(tooltipText), findsNothing);
// Move the mouse over the text and wait for the tooltip to appear.
final Finder tooltip = find.byType(Tooltip);
await gesture.moveTo(tester.getCenter(tooltip));
// Wait half a second and the tooltip should still not be visible.
await tester.pump(const Duration(milliseconds: 500));
expect(find.text(tooltipText), findsNothing);
// Wait another half a second and the tooltip should be visible now.
await tester.pump(const Duration(milliseconds: 500));
expect(find.text(tooltipText), findsOneWidget);
// Move the mouse away and wait for the tooltip to disappear.
await gesture.moveTo(const Offset(1.0, 1.0));
await tester.pump();
// Wait another second and the tooltip should be gone.
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
expect(find.text(tooltipText), findsNothing);
});
}