mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix: Delay showing tooltip during page transition (#167614)
Fix: Delay showing tooltip during page transition fixes: #167359 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This commit is contained in:
parent
e78754267b
commit
fb18bb4e76
@ -564,6 +564,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
|
||||
if (!_visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
_controller.forward();
|
||||
_timer?.cancel();
|
||||
_timer = showDuration == null ? null : Timer(showDuration, _controller.reverse);
|
||||
@ -927,8 +928,16 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
|
||||
child: widget.child,
|
||||
);
|
||||
|
||||
bool visible = _visible;
|
||||
|
||||
// Check if there's an ongoing route transition
|
||||
final ModalRoute<dynamic>? route = ModalRoute.of(context);
|
||||
if (route?.secondaryAnimation != null && route!.secondaryAnimation!.isAnimating) {
|
||||
visible = false;
|
||||
}
|
||||
|
||||
// Only check for gestures if tooltip should be visible.
|
||||
if (_visible) {
|
||||
if (visible) {
|
||||
result = _ExclusiveMouseRegion(
|
||||
onEnter: _handleMouseEnter,
|
||||
onExit: _handleMouseExit,
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -3478,6 +3479,49 @@ void main() {
|
||||
);
|
||||
expect(tester.element(textAncestors.first).size, equals(tooltipConstraints.biggest));
|
||||
});
|
||||
|
||||
// This is a regression test for https://github.com/flutter/flutter/issues/167359.
|
||||
testWidgets('Tooltip does not show while transitioning from another page', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const Center(child: Tooltip(message: 'Hello', child: Text('World'))),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return TextButton(
|
||||
onPressed:
|
||||
() => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute<void>(
|
||||
builder:
|
||||
(BuildContext context) =>
|
||||
Scaffold(appBar: AppBar(title: const Text('Second Page'))),
|
||||
),
|
||||
),
|
||||
child: const Text('Go to Second Page'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Go to Second Page'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await gesture.addPointer();
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await gesture.moveTo(tester.getCenter(find.text('World')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> setWidgetForTooltipMode(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user