Skip to content

[web] onTextScaleFactorChanged not firing? #178271

@ditman

Description

@ditman

(Internal issue: b/457959782)

Steps to reproduce

I'd expect this app to update the text scale factor as I change Font settings in Chrome:

  • Run the provided main.dart in Chrome
  • In a separate tab, go to "Customize fonts" in the Chrome settings, and change the "Font size" slider (by default it should be at 16), make it larger. The larger, the more apparent the issue.
    • (Observe that this immediately scale any non-flutter website)

Expected results

  • The demo app I posted, should update the displayed value of the text scale factor, and its font should adapt to the new size

Actual results

  • The text scale factor remains fixed at whatever was when the app first started.

(Note that reloading updates the value, so the value is computed correctly, it seems to just be the onTextScaleFactorChanged callback not firing)

Code sample

main.dart
import 'package:flutter/foundation.dart';
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 Demo',
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double _textScaleFactor = PlatformDispatcher.instance.textScaleFactor;

  @override
  void initState() {
    super.initState();
    // This is not firing as browser settings are updated!
    PlatformDispatcher.instance.onTextScaleFactorChanged = (() {
      setState(() {
        _textScaleFactor = PlatformDispatcher.instance.textScaleFactor;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: .center,
          children: [
            const Text('The current textScaleFactor is:'),
            Text(
              '$_textScaleFactor',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

n/a

Logs

Logs

n/a

Flutter Doctor output

Doctor output
$ flutter doctor -v
[!] Flutter (Channel master, 3.38.0-1.0.pre-475, on Debian GNU/Linux rodete 6.16.9-1rodete1-amd64, locale en_US.UTF-8) [792ms]
    • Flutter version 3.38.0-1.0.pre-475 on channel master at /work/flutter/flutter
    ! Upstream repository [email protected]:ditman/flutter-flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to [email protected]:ditman/flutter-flutter.git to dismiss this error.
    • Framework revision f892a5a3cc (4 hours ago), 2025-11-10 14:35:58 -0500
    • Engine revision f892a5a3cc
    • Dart version 3.11.0 (build 3.11.0-114.0.dev)
    • DevTools version 2.52.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
      omit-legacy-version-file, enable-lldb-debugging
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

...

[✓] Connected device (2 available) [136ms]
    • Chrome (web)    • chrome • web-javascript • Google Chrome 142.0.7444.134

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: typographyText rendering, possibly libtxtengineflutter/engine related. See also e: labels.good first issueRelatively approachable for first-time contributorsr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions