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(