Skip to content

Add error message when lerping between TextStyles different inherit values#112837

Merged
auto-submit[bot] merged 6 commits intoflutter:masterfrom
LongCatIsLooong:text-style-lerp-guards
Oct 7, 2022
Merged

Add error message when lerping between TextStyles different inherit values#112837
auto-submit[bot] merged 6 commits intoflutter:masterfrom
LongCatIsLooong:text-style-lerp-guards

Conversation

@LongCatIsLooong
Copy link
Contributor

Fixes #43358

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Oct 4, 2022
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 wonder if I should mention this is just mimicking Theme.of. Maybe there're better examples?

Copy link
Contributor

Choose a reason for hiding this comment

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

This error report is probably comprehensive enough without this additional explanation. Also: it's not clear that we really want to advocate calling ThemeData.localize, since that's done automatically when the app's locale is finalized. I think it would be best to leave this part of the error report out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no ThemeData.merge so the example is really awkward. Should I say instead of transitioning to Theme.of(context) you should transition to isDark ? ThemeData.dark() : ThemeData()?

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. Just some wordsmithing and error message smithing.

/// [inherit] value.
///
/// Properties that don't have explicit values or other default values to fall
/// back to will revert to the defaults defined in the text shaper: white in
Copy link
Contributor

Choose a reason for hiding this comment

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

"text shaper"? Will developers know what that refers to? Unless "text shaper" refers to something that will make this point easier to understand, just explaining what the defaults are is probably enough.

Note also: I'm surprised that the default color is white (instead of black).

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 mostly copied these defaults without actually checking (the font size is correct). It could be black let me check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it's correct. Should I say "defined in ui.Paragraph" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got rid of "text shaper"

/// The package name should be provided by the `package` argument in the
/// constructor.
List<String>? get fontFamilyFallback => _package != null && _fontFamilyFallback != null ? _fontFamilyFallback!.map((String str) => 'packages/$_package/$str').toList() : _fontFamilyFallback;
List<String>? get fontFamilyFallback => _package != null ? _fontFamilyFallback?.map((String str) => 'packages/$_package/$str').toList() : _fontFamilyFallback;
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be slightly easier to ready if the simple case was first:

List<String>? get fontFamilyFallback => _package == null ? _fontFamilyFallback :  _fontFamilyFallback?.map((String str) => 'packages/$_package/$str').toList();

}

/// Interpolate between two text styles.
/// Interpolate between two text styles for animated transitions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why include the "for animation transitions" qualifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation does things to keep the transition smooth (e.g.: fontSize: ui.lerpDouble(a.fontSize ?? b.fontSize, b.fontSize ?? a.fontSize, t),), that doesn't really make sense for anything other than transitions.

/// Interpolate between two text styles.
/// Interpolate between two text styles for animated transitions.
///
/// This will not work well if the styles don't set the same fields. When this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// This will not work well if the styles don't set the same fields. When this
/// Interpolation will not work well if the styles don't specify the same fields. When this

/// Interpolate between two text styles for animated transitions.
///
/// This will not work well if the styles don't set the same fields. When this
/// happens, to keep the transition smooth, the implementation uses the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// happens, to keep the transition smooth, the implementation uses the
/// happens, to keep the interpolated transition smooth, the implementation uses the

ErrorSpacer(),
ErrorHint(
'In general, TextStyle.lerp only works well when both TextStyles have '
'the same "inherit" value, and set roughly the same fields.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'the same "inherit" value, and set roughly the same fields.',
'the same "inherit" value, and specify roughly the same fields.',

Also: Do we really need to say "roughly" the same fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed roughly

Copy link
Contributor

Choose a reason for hiding this comment

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

This error report is probably comprehensive enough without this additional explanation. Also: it's not clear that we really want to advocate calling ThemeData.localize, since that's done automatically when the app's locale is finalized. I think it would be best to leave this part of the error report out.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 7, 2022
@auto-submit auto-submit bot merged commit 5d4f240 into flutter:master Oct 7, 2022
@LongCatIsLooong LongCatIsLooong deleted the text-style-lerp-guards branch October 7, 2022 06:06
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnimatedTheme throws exceptions when lerping between default Theme and ThemeData.dark()

2 participants