Don't display empty tooltips (Tooltips with empty message property) (#87638)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user