Skip to content

Incorrect documentation on TextPainter #165047

@JaffaKetchup

Description

@JaffaKetchup

Steps to reproduce

The TextPainter documentation states:

The default text style is white. To change the color of the text, pass a TextStyle object to the TextSpan in text.

This is not true on all platforms. On web, the default color is black (to contrast to the default white background, opposite to native platforms).

It may also be worth stating the differences in text color and background color elsewhere (maybe on CustomPaint, Canvas, or CustomPainter)?

Expected results

The documentation should be updated to note the difference.

Actual results

The documentation is incorrect.

Code sample

MRE

Run on a web platform, and on a native platform.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'flutter_map Demo',
        theme: ThemeData(
          useMaterial3: true,
          colorSchemeSeed: const Color(0xFF8dea88),
          brightness: Brightness.light,
        ),
        home: CustomPaint(
          painter: Painter(),
        ));
  }
}

class Painter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    TextPainter(text: TextSpan(text: 'hello'), textDirection: TextDirection.ltr)
      ..layout()
      ..paint(canvas, Offset.zero);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}

Screenshots or Video

Image

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel master, 3.30.0-1.0.pre.553, on Microsoft Windows [Version 10.0.26120.3380], locale en-GB) [5.3s]
    • Flutter version 3.30.0-1.0.pre.553 on channel master at C:\Users\lukas\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 463e751640 (20 hours ago), 2025-03-11 13:00:17 -0400
    • Engine revision 463e751640
    • Dart version 3.8.0 (build 3.8.0-171.0.dev)
    • DevTools version 2.44.0

[√] Windows Version (11 Home 64-bit, 24H2, 2009) [3.4s]

[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc3) [4.3s]
    • Android SDK at C:\Users\lukas\AppData\Local\Android\sdk
    • Platform android-35, build-tools 36.0.0-rc3
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29)
    • All Android licenses accepted.

[√] Chrome - develop for the web [202ms]
    • CHROME_EXECUTABLE = C:\Program Files\Google\Chrome Dev\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.10.4) [201ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.10.35027.167
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2024.2) [27ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29)

[√] VS Code, 64-bit edition (version 1.97.2) [25ms]
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.106.0

[√] Connected device (3 available) [375ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26120.3380]
    • Chrome (web)      • chrome  • web-javascript • unknown
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 134.0.3124.51

[√] Network resources [404ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: typographyText rendering, possibly libtxtd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions