-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[Material] Implement TooltipTheme and Tooltip.textStyle, fix Tooltip debugLabel, update Tooltip defaults #36030
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
Conversation
…property Not documented yet, still needs tests for TooltipTheme.
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good although I'd like to see if we can avoid the Theme brightness dependency. Most of feedback is trivial wordsmithing.
Please add:
DebugFillProperties tests like https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/bottom_sheet_theme_test.dart#L22 and
https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/bottom_sheet_theme_test.dart#L34
A copyWith/hashCode/== test like this: https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/bottom_sheet_theme_test.dart#L10
A test that verifies the theme's default values (even though they're all null; so we don't regress) like this:
https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/button_theme_test.dart#L9
| /// A theme for customizing the size, shape, and color of the tab bar indicator. | ||
| final TabBarTheme tabBarTheme; | ||
|
|
||
| /// A theme for customizing the various properties of [Tooltip]s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "various", maybe visual.
| /// user long presses on the widget. | ||
| /// | ||
| /// All of the arguments except [child] and [decoration] must not be null. | ||
| const Tooltip({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor doc isn't right (anymore):
/// All of the arguments except [child] and [decoration] must not be null.
Instead of this point about tooltip positioning, which probably belongs somewhere else, you could make a brief point about how the constructor parameters relate to TooltipTheme.
/// By default, tooltips prefer to appear below the [child] widget when the
/// user long presses on the widget.
|
|
||
| /// The style to use for the message of the tooltip. | ||
| /// | ||
| /// If null, the message's [TextStyle] will be determined based on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really nice if this bright/dark dependency wasn't needed. Can't we just use ThemeData.textTheme? It appears to be black/white already - https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/theme_data.dart#L224
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do the following instead:
final TextStyle defaultTextStyle = theme.textTheme.body1.copyWith(
color: theme.colorScheme.onSurface,
);
As discussed offline, it'd be a breaking change, but it'd be closer aligned to the material spec and removes the dependency on Brightness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theming is specified by the material spec here: https://material.io/design/components/tooltips.html#theming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the textTheme to correspond with what is expected by Material
| final TooltipThemeData tooltipTheme = TooltipTheme.of(context); | ||
| final bool excludeFromSemantics = widget.excludeFromSemantics ?? tooltipTheme.excludeFromSemantics ?? _defaultExcludeFromSemantics; | ||
|
|
||
| waitDuration = widget.waitDuration ?? tooltipTheme.waitDuration ?? _defaultWaitDuration; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE
| ? theme.typography.white.merge(theme.textTheme).body1 | ||
| : theme.typography.white.merge(theme.primaryTextTheme).body1; | ||
|
|
||
| final BoxDecoration defaultDecoration = BoxDecoration( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a static const _defaultDecoration? Note that
BorderRadius.circular(4) == const BorderRadius.all(Radius.circular(4))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this be achieved for the color Colors.grey[700].withOpacity(0.9)? I could use Color(0xFF616161), but calling .withOpacity() makes it a non-const value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after our discussion, if we decide to do a breaking change, the defaults would change as follows:
final BoxDecoration defaultDecoration = BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: const BorderRadius.all(Radius.circular(4)),
);
| assert(t != null); | ||
| assert(a?.preferBelow == b?.preferBelow); | ||
| assert(a?.excludeFromSemantics == b?.excludeFromSemantics); | ||
| if (a == null && b == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this statement should be first.
| ); | ||
| } | ||
|
|
||
| /// Linearly interpolate between two tooltip themes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to prohibit changing preferBelow and excludeFromSemantics, we should document that. It might be better to use this kind of "interpolation" instead:
preferBelow: t < 0.5 ? a.preferBelow: b.preferBelow
Ideally this stuff wouldn't change but it doesn't seem worth creating a corner case for the odd case where it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll use that interpolation style instead. It seems to be better than just blocking them outright.
| ), | ||
| super(key: key, child: child); | ||
|
|
||
| /// Specifies the properties for descendant [Tooltip] widgets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifies the => The
| /// Typical usage is as follows: | ||
| /// | ||
| /// ```dart | ||
| /// TooltipTheme theme = TooltipTheme.of(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TooltipThemeData theme = ...
| /// Specifies the properties for descendant [Tooltip] widgets. | ||
| final TooltipThemeData data; | ||
|
|
||
| /// The closest instance of this class that encloses the given context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the conventional boilerplate for an inherited widget; it's not correct for this theme. This of method returns the closest TooltipTheme ancestor's [data] value, and if there is no TooltipTheme ancestor, then it returns the current [Theme]'s tooltipTheme. Apps can assume that the returned value is not null.
|
I've implemented most of the code review suggestions and added the default tests for TooltipThemeData. I'm still currently waiting on what the default values for the border radii, background color, text color and opacity values should be. |
|
I've received feedback on what the default tooltip |
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
|
||
| /// A theme for customizing the visual properties of [Tooltip]s. | ||
| /// | ||
| /// This is the value returned from [Tooltip.of]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from [TooltipTheme.of]
| /// tree. | ||
| /// | ||
| /// Defaults to false. A tooltip will add a [Semantics.label] that is set to | ||
| /// [Tooltip.message]. Set this property to true if a custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean ... true if the app is going to provide its own custom semantics label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I'll update that
| /// tree. | ||
| /// | ||
| /// By default, [Tooltip]s will add a [Semantics.label] that is set to | ||
| /// [Tooltip.message]. Set this property to true if a custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as earlier
| /// The properties for descendant [Tooltip] widgets. | ||
| final TooltipThemeData data; | ||
|
|
||
| /// The closest instance of this class' [data] value that encloses the given |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class' => class's
Maybe this could be a little clearer.
Returns the [data] from the closest [TooltipTheme] ancestor.
| /// By default, tooltips prefer to appear below the [child] widget when the | ||
| /// user long presses on the widget. | ||
| /// By default, tooltips should adhere to the | ||
| /// [Material specifications](https://material.io/design/components/tooltips.html#spec). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifications => specification
…debugLabel, update Tooltip defaults (flutter#36030) * Implement TooltipThemeData and TooltipTheme * Add tooltip text style property * Update default tooltip text style and decoration to match Material specification * Fix debugLabel incorrectly labeling "white" as "black", and vice versa by default
…Tooltip debugLabel, update Tooltip defaults (flutter#36030)" (flutter#36851) This reverts commit 62158a1.
Description
textStyleproperty, granting more fine-grained control to developers to update the tooltip's text message.Fix
debugLabelto use the correct color when reporting the message's textStyleBreaking change: Updating default tooltip
decorationto the following:textStyleto the following:Tooltip Before Breaking change:


Tooltip After Breaking change:


Related Issues
Fixes #35513
Related to #33654
Related to #25844
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?