From c575638443acfc7f99d02e62daaf64823aa7c844 Mon Sep 17 00:00:00 2001 From: Luka S Date: Thu, 27 Mar 2025 04:45:08 +0000 Subject: [PATCH] Update documentation on `TextPainter` to note default color differences (#165048) 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 - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] 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]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- packages/flutter/lib/src/painting/text_painter.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index ede8f8cd1f..15216d89bb 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -583,8 +583,9 @@ 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`. +/// The default text style color is white on non-web platforms and black on +/// the web. If developing across both platforms, always set the text color +/// explicitly. class TextPainter { /// Creates a text painter that paints the given text. ///