Don't display empty tooltips (Tooltips with empty message property) (#87638)

This commit is contained in:
BambinoUA
2021-09-10 20:12:03 +03:00
committed by GitHub
parent 77c2705991
commit 7736b9eef0
2 changed files with 32 additions and 0 deletions

View File

@@ -475,6 +475,12 @@ class _TooltipState extends State<Tooltip> 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);

View File

@@ -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<void> setWidgetForTooltipMode(WidgetTester tester, TooltipTriggerMode triggerMode) async {