Skip to content

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Sep 13, 2022

Now that TextPainters must be disposed, it makes some sense to wrap this functionality in a utility method.

In customer applications, it is very common to use a text painter to figure out the width of something you want to animate, and then immediately dispose of the painter. This is probably ok because of caching that SkParagraph will do.

I'm a little bit on the fence about whether we should be promoting this, but there are at least 100 callsites in Google's monorepo that use this pattern (likely with some cargo-culting since the code is basically the same everywhere) - so if there's some better way I'm open to hearing about it :)

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. labels Sep 13, 2022
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 13, 2022
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 13, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 13, 2022

auto label is removed for flutter/flutter, pr: 111493, due to - The status or check suite Linux web_long_running_tests_5_5 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 13, 2022
static double computeWidth({
required InlineSpan text,
TextAlign textAlign = TextAlign.start,
TextDirection? textDirection,
Copy link
Contributor

Choose a reason for hiding this comment

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

TextDirection must be non null I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was copied from the TextPainter ctor. I'd like to keep the types the same for ease of migration.

If we want to update this we should update the ctor as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh but I see what you're saying, on the regular object we can set this to some value later, whereas we can't with this method. Ok. In that case, I'll file a follow upt o make it non-nullable.

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 f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants