From 7736b9eef03124c46418dea6718e6c412a375a00 Mon Sep 17 00:00:00 2001 From: BambinoUA <45417992+bambinoua@users.noreply.github.com> Date: Fri, 10 Sep 2021 20:12:03 +0300 Subject: [PATCH] Don't display empty tooltips (Tooltips with empty `message` property) (#87638) --- .../flutter/lib/src/material/tooltip.dart | 6 +++++ .../flutter/test/material/tooltip_test.dart | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index 5df8ad5589..13cc4a5bbb 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -475,6 +475,12 @@ class _TooltipState extends State with SingleTickerProviderStateMixin { @override Widget build(BuildContext context) { + // If message is empty then no need to create a tooltip overlay to show + // the empty black container so just return the wrapped child as is or + // empty container if child is not specified. + if (widget.message.isEmpty) { + return widget.child ?? const SizedBox(); + } assert(Overlay.of(context, debugRequiredFor: widget) != null); final ThemeData theme = Theme.of(context); final TooltipThemeData tooltipTheme = TooltipTheme.of(context); diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 601091f9a6..8e7e113168 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -1497,6 +1497,32 @@ void main() { await testGestureLongPress(tester, tooltip); expect(find.text(tooltipText), findsNothing); }); + + testWidgets('Tooltip should not be shown with empty message (with child)', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Tooltip( + message: tooltipText, + child: Text(tooltipText), + ), + ), + ); + expect(find.text(tooltipText), findsOneWidget); + }); + + testWidgets('Tooltip should not be shown with empty message (without child)', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Tooltip( + message: tooltipText, + ), + ), + ); + expect(find.text(tooltipText), findsNothing); + if (tooltipText.isEmpty) { + expect(find.byType(SizedBox), findsOneWidget); + } + }); } Future setWidgetForTooltipMode(WidgetTester tester, TooltipTriggerMode triggerMode) async {