Skip to content

Conversation

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Jul 12, 2019

Description

  1. Implements a TooltipTheme widget that allows all existing properties to be themeable.

Screen Shot 2019-07-19 at 1 25 50 PM

Screen Shot 2019-07-19 at 1 25 40 PM

  1. Introduces the textStyle property, granting more fine-grained control to developers to update the tooltip's text message.

Screen Shot 2019-07-19 at 1 31 22 PM

Screen Shot 2019-07-19 at 1 31 06 PM

  1. Fix debugLabel to use the correct color when reporting the message's textStyle

  2. Breaking change: Updating default tooltip decoration to the following:

  • Brightness.light
BoxDecoration(
  color: Colors.grey[700].withOpacity(0.9),
  borderRadius: const BorderRadius.all(Radius.circular(4)),
);
  • Brightness.dark
BoxDecoration(
  color: Colors.white.withOpacity(0.9), // new
  borderRadius: const BorderRadius.all(Radius.circular(4)),
);
  1. Breaking change: Updating default textStyle to the following:
  • Brightness.light
theme.textTheme.body1.copyWith(
  color: Colors.white, // new
  debugLabel: theme.textTheme.body1.debugLabel.replaceAll('white', 'black'), // fixes debugLabel
);
  • Brightness.dark
theme.textTheme.body1.copyWith(
  color: Colors.black, // new
  debugLabel: theme.textTheme.body1.debugLabel.replaceAll('white', 'black'), // fixes debugLabel
);

Tooltip Before Breaking change:
Screen Shot 2019-07-19 at 3 21 15 PM
Screen Shot 2019-07-19 at 3 21 26 PM

Tooltip After Breaking change:
Screen Shot 2019-07-19 at 3 19 39 PM
Screen Shot 2019-07-19 at 3 20 08 PM

Related Issues

Fixes #35513
Related to #33654
Related to #25844

Tests

I added the following tests:

  • Several tests verifying passing down of TooltipTheme properties (color, location, height, decoration, semantics, show and wait durations to reveal and hide tooltip)
  • Tests for textStyle implementation
  • Test to verify debugLabel for light and dark theme

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@shihaohong shihaohong added c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jul 12, 2019
@shihaohong shihaohong changed the title WIP - Tooltip Theme Tooltip Theme Jul 12, 2019
@shihaohong shihaohong requested a review from HansMuller July 12, 2019 00:51
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// 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.
Copy link
Contributor

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({
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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;
Copy link
Contributor

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(
Copy link
Contributor

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))

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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);
Copy link
Contributor

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.
Copy link
Contributor

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.

@shihaohong
Copy link
Contributor Author

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.

@shihaohong shihaohong added the c: API break Backwards-incompatible API changes label Jul 17, 2019
@shihaohong
Copy link
Contributor Author

I've received feedback on what the default tooltip decoration and textStyle should be, and this PR is now ready for review.

@shihaohong shihaohong changed the title Tooltip Theme [Material] Implement Tooltip Theme, along with fixes to default Tooltip properties Jul 17, 2019
@shihaohong shihaohong requested a review from HansMuller July 18, 2019 04:36
@HansMuller HansMuller mentioned this pull request Jul 18, 2019
9 tasks
@shihaohong shihaohong changed the title [Material] Implement Tooltip Theme, along with fixes to default Tooltip properties [Material] Implement Tooltip Jul 19, 2019
@shihaohong shihaohong changed the title [Material] Implement Tooltip [Material] Implement TooltipTheme, fix Tooltip bugs, update Tooltip defaults Jul 19, 2019
Copy link
Contributor

@HansMuller HansMuller left a 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].
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifications => specification

@shihaohong shihaohong changed the title [Material] Implement TooltipTheme, fix Tooltip bugs, update Tooltip defaults [Material] Implement TooltipTheme and Tooltip.textStyle, fix Tooltip debugLabel, update Tooltip defaults Jul 22, 2019
@shihaohong shihaohong merged commit 62158a1 into flutter:master Jul 24, 2019
@shihaohong shihaohong deleted the tooltip-theme branch July 24, 2019 15:24
shihaohong pushed a commit that referenced this pull request Jul 24, 2019
…Tooltip debugLabel, update Tooltip defaults (#36030)"

This reverts commit 62158a1.
shihaohong pushed a commit that referenced this pull request Jul 24, 2019
…Tooltip debugLabel, update Tooltip defaults (#36030)" (#36851)

This reverts commit 62158a1.
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
…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
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
…Tooltip debugLabel, update Tooltip defaults (flutter#36030)" (flutter#36851)

This reverts commit 62158a1.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: API break Backwards-incompatible API changes c: new feature Nothing broken; request for a new capability f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global configuration for Tooltip

3 participants