Skip to content

Add Tooltip default vertical padding #103395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/flutter/lib/src/material/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class Tooltip extends StatefulWidget {

/// The amount of space by which to inset the tooltip's [child].
///
/// Defaults to 16.0 logical pixels in each direction.
/// On mobile, defaults to 16.0 logical pixels horizontally and 4.0 vertically.
/// On desktop, defaults to 8.0 logical pixels horizontally and 4.0 vertically.
final EdgeInsetsGeometry? padding;

/// The empty space that surrounds the tooltip.
Expand Down Expand Up @@ -403,11 +404,11 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
case TargetPlatform.macOS:
case TargetPlatform.linux:
case TargetPlatform.windows:
return const EdgeInsets.symmetric(horizontal: 8.0);
return const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
return const EdgeInsets.symmetric(horizontal: 16.0);
return const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0);
}
}

Expand Down
22 changes: 12 additions & 10 deletions packages/flutter/test/material/tooltip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,16 @@ void main() {
tooltipKey.currentState?.ensureTooltipVisible();
await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

final RenderBox tip = tester.renderObject(
_findTooltipContainer(tooltipText),
);
final RenderBox tip = tester.renderObject(_findTooltipContainer(tooltipText));
expect(tip.size.height, equals(32.0));
expect(tip.size.width, equals(74.0));
expect(tip, paints..rrect(
rrect: RRect.fromRectAndRadius(tip.paintBounds, const Radius.circular(4.0)),
color: const Color(0xe6616161),
));

final Container tooltipContainer = tester.firstWidget<Container>(_findTooltipContainer(tooltipText));
expect(tooltipContainer.padding, const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0));
});

testWidgets('Tooltip default size, shape, and color test for Desktop', (WidgetTester tester) async {
Expand All @@ -830,14 +831,15 @@ void main() {
final RenderParagraph tooltipRenderParagraph = tester.renderObject<RenderParagraph>(find.text(tooltipText));
expect(tooltipRenderParagraph.textSize.height, equals(12.0));

final RenderBox tooltipContainer = tester.renderObject(
_findTooltipContainer(tooltipText),
);
expect(tooltipContainer.size.height, equals(24.0));
expect(tooltipContainer, paints..rrect(
rrect: RRect.fromRectAndRadius(tooltipContainer.paintBounds, const Radius.circular(4.0)),
final RenderBox tooltipRenderBox = tester.renderObject(_findTooltipContainer(tooltipText));
expect(tooltipRenderBox.size.height, equals(24.0));
expect(tooltipRenderBox, paints..rrect(
rrect: RRect.fromRectAndRadius(tooltipRenderBox.paintBounds, const Radius.circular(4.0)),
color: const Color(0xe6616161),
));

final Container tooltipContainer = tester.firstWidget<Container>(_findTooltipContainer(tooltipText));
expect(tooltipContainer.padding, const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows}));

testWidgets('Can tooltip decoration be customized', (WidgetTester tester) async {
Expand Down Expand Up @@ -1437,7 +1439,7 @@ void main() {
tip = tester.renderObject(
_findTooltipContainer(tooltipText),
);
expect(tip.size.height, equals(56.0));
expect(tip.size.height, equals(64.0));
});

testWidgets('Tooltip text displays with richMessage', (WidgetTester tester) async {
Expand Down