From fb18bb4e766dc0d313a24276688a3ebb9cbc32b6 Mon Sep 17 00:00:00 2001 From: Kishan Rathore <34465683+rkishan516@users.noreply.github.com> Date: Thu, 1 May 2025 00:14:36 +0530 Subject: [PATCH] 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. --- .../flutter/lib/src/material/tooltip.dart | 11 ++++- .../flutter/test/material/tooltip_test.dart | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index cdf7338f3b2..a9db965ad66 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -564,6 +564,7 @@ class TooltipState extends State 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 with SingleTickerProviderStateMixin { child: widget.child, ); + bool visible = _visible; + + // Check if there's an ongoing route transition + final ModalRoute? 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, diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 80e26ecd36d..8666241a6cd 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -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( + 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 setWidgetForTooltipMode(