Skip to content
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

Update documentation on TextPainter to note default color differences #165048

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JaffaKetchup
Copy link

@JaffaKetchup JaffaKetchup commented Mar 12, 2025

This change only changes the documentation of TextPainter.

Previously, the documentation was incorrect in stating that the default text color was white. It changes depending on platform to be contrasted to the canvas' background color.

This is in an "important" box because it affects apps working on native & web, and is relatively easy to miss.

It may be worth documenting this elsewhere?

Fixes #165047

Pre-launch Checklist

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

@github-actions github-actions 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 Mar 12, 2025
@JaffaKetchup JaffaKetchup changed the base branch from main to master March 12, 2025 12:32
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

I believe the default is current set by flutter not skparagraph / canvaskit. (It looks like we're not setting default text colors for the canvaskit, instead the default is from here).
the non-web default is from here.
And it looks like the canvaskit backend default is from here.
The wasm implementation here

@mdebbar does it make sense to update one of the defaults so it's consistent between backends?

@@ -583,8 +583,15 @@ class _LineCaretMetrics {
/// changes, return to step 2. If the text to be painted changes,
/// return to step 1.
///
/// The default text style is white. To change the color of the text,
/// pass a [TextStyle] object to the [TextSpan] in `text`.
/// > [!IMPORTANT]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think dartdoc supports this markdown extension. Even if it does, this doesn't feel THAT important to warrant a highlighted section.

Copy link
Author

Choose a reason for hiding this comment

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

Dartdoc does now support this - can't link it right now, but search for "> [!IMPORTANT]" with quotes and you'll get to the issue/PR. Whether or not it's good to use here, I feel it is - in my case, it wasn't immediately clear why the texts were different colours since I couldn't see the background.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh dart-lang/dartdoc#3995. TIL thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't "The default text style color is white on non-web platforms and black on the web" suffice? For API docs I would prefer less reading if we can convey the same message.

Copy link
Author

Choose a reason for hiding this comment

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

I've reduced it, using that text for the first line. There's still the second part, since I think that's also important, but I've also reduced that.

@JaffaKetchup
Copy link
Author

does it make sense to update one of the defaults so it's consistent between backends?

Probably completely misunderstanding you here, and I cant see where the colour is actually set in the second link, so I don't know which backend you'd suggest changing - but doesn't it make sense for the colour to be black on white on web (regardless of backend) and white on black on native (regardless of backend). And from my testing - although I can't fully remember/be sure - I didn't notice a difference in the text colour whether I was using wasm or not on web - because of course, they should both be black on white to be visible.

@LongCatIsLooong
Copy link
Contributor

does it make sense to update one of the defaults so it's consistent between backends?

Probably completely misunderstanding you here, and I cant see where the colour is actually set in the second link, so I don't know which backend you'd suggest changing - but doesn't it make sense for the colour to be black on white on web (regardless of backend) and white on black on native (regardless of backend). And from my testing - although I can't fully remember/be sure - I didn't notice a difference in the text colour whether I was using wasm or not on web - because of course, they should both be black on white to be visible.

Yeah you're right that the second link isn't where the default is set. The default is actually from canvaskit. I'll update the link.

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 framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect documentation on TextPainter
2 participants