Skip to content

[A11y] Connect the accessibility override controls to the app - #10065

Open
victorsanni wants to merge 9 commits into
flutter:masterfrom
victorsanni:a11y-override-controls
Open

victorsanni wants to merge 9 commits into
flutter:masterfrom
victorsanni:a11y-override-controls

Conversation

@victorsanni

@victorsanni victorsanni commented Nov 2, 2026 •

Copy link
Copy Markdown

Part of #9893.

This connects the text scale, bold text and high contrast overrides on the Accessibility page to the app. They go through ext.flutter.viewMetricsOverride, which flutter/flutter#192764 added and flutter/flutter#194311 made take effect in the app.

The new ViewMetricsOverrideClient:

  • Reads the app's overrides once the extension is registered, then follows the replies and the Flutter.ServiceExtensionStateChanged events. It listens to the events itself, because ServiceExtensionManager would turn their JSON value into a string.
  • Starts every write from the overrides that the app last reported and changes only the given metrics, so overrides that other clients set stay.

On the page:

  • Text scale sends textScaling: [[1, factor]], which scales text linearly. Until text scale is overridden, the page shows "System Default", because 1.0 is an override too. A reset button removes the override.
  • The bold text and high contrast switches send boldText and highContrast. Turning one off removes the override, so the app goes back to the platform's setting.
  • The Screen Reader Debugger switch is unchanged and still not connected to the app. It moves below the other switches, outside their tooltip.
  • The controls show what the app reports, including changes from other clients. While a change is on its way to the app, the control shows the new value.
  • While the app has not registered the extension, for example before it starts, in a profile build or on an older Flutter version, the controls are disabled and a tooltip says why.

Caveats:

  • Only the implicit view is overridden, because the extension cannot list views yet.
  • A hot restart removes these overrides, since it empties the app's registry. Restoring them is left to a follow-up.
  • The extension replaces a view's whole entry, so a write from DevTools removes a change that app code made with debugSetViewMetricsOverride, which the app does not report. It also removes a change that another client made after DevTools last heard from the app, and before the write arrived.
  • On a Flutter version that has Scaffold view metrics overrides flutter#192764 but not Apply view metrics overrides below the framework flutter#194311, the controls are enabled but change nothing.
  • There is no release note, because the page is behind the accessibility experiment flag.

The client tests use a fake of the extension that parses writes like the app and, like the VM service, never answers a call that is in flight when its isolate exits. They cover following the app, failures, hot restarts, and calls that a hot restart or dispose interrupts. Controller and widget tests cover what the controls send and show. The devtools_test fakes can now emit extension events and replace the main isolate.

After this PR:

  • Move brightness to this extension.
  • Fix for the brightness override that is not restored after a hot restart while this page is open.
  • Restore the text scale, bold text and high contrast overrides after a hot restart.
  • Connect the Screen Reader Debugger switch to the semantics debugger, which needs a service extension in Flutter first.

Pre-launch Checklist

General checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I updated/added relevant documentation (doc comments with ///).

Issues checklist

Tests checklist

  • I added new tests to check the change I am making...
  • OR there is a reason for not adding tests, which I explained in the PR description.

AI-tooling checklist

  • I did not use any AI tooling in creating this PR.
  • OR I did use AI tooling, and...
    • I read the AI contributions guidelines and agree to follow them.
    • I reviewed all AI-generated code before opening this PR.
    • I understand and am able to discuss the code in this PR.
    • I have verifed the accuracy of any AI-generated text included in the PR description.
    • I commit to verifying the accuracy of any AI-generated code or text that I upload in response to review comments.

Feature-change checklist

  • This PR does not change the DevTools UI or behavior and...
    • I added the release-notes-not-required label or left a comment requesting the label be added.
  • OR this PR does change the DevTools UI or behavior and...
    • I added an entry to packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.
    • I included before/after screenshots and/or a GIF demo of the new UI to my PR description.
    • I ran the DevTools app locally to manually verify my changes.

build.yaml badge

If you need help, consider asking for help on Discord.

Adds ViewMetricsOverrideClient, a client for ext.flutter.viewMetricsOverride,
and connects the text scale, bold text, screen reader and high contrast
controls of the Accessibility page to it.
@victorsanni
victorsanni requested a review from a team as a code owner November 2, 2026 18:04
@victorsanni
victorsanni requested review from srawlins and removed request for a team November 2, 2026 18:04

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for the ext.flutter.viewMetricsOverride service extension, enabling users to override accessibility settings (text scale, bold text, screen reader, and high contrast) in debug builds. It introduces ViewMetricsOverrideClient to manage the service extension, handles state restoration across hot restarts, and updates the accessibility controller and UI overrides pane. Feedback focuses on improving error handling: rethrowing and catching service extension failures to notify users, handling background errors with .catchError, adding a defensive check against division by zero in _textScaleFactor, and using a try-finally block to ensure the text scale slider resets properly on failure.

Comment on lines +184 to 186
Future<void> _setOverride(String metric, Object? value) async {
await _viewMetricsOverrideClient?.updateOverrides({metric: value});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

[CONCERN] Catching the exception here and pushing a notification via notificationService provides a much better user experience. It ensures that if the service extension call fails, the user is notified immediately rather than the UI silently failing to apply the override.

Suggested change
Future<void> _setOverride(String metric, Object? value) async {
await _viewMetricsOverrideClient?.updateOverrides({metric: value});
}
Future<void> _setOverride(String metric, Object? value) async {
try {
await _viewMetricsOverrideClient?.updateOverrides({metric: value});
} catch (e) {
notificationService.push('Failed to set override: $e');
}
}
References
  1. Prioritize logic, performance on the UI thread, and architectural consistency. (link)

Comment on lines +191 to 196
static double? _textScaleFactor(Object? textScaling) {
if (textScaling case [[final num unscaled, final num scaled], ...]) {
return scaled / unscaled;
}
return null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

[CONCERN] Defensively check if unscaled is zero to avoid division by zero, which would result in double.infinity or double.nan and potentially cause layout or rendering issues in the UI.

Suggested change
static double? _textScaleFactor(Object? textScaling) {
if (textScaling case [[final num unscaled, final num scaled], ...]) {
return scaled / unscaled;
}
return null;
}
static double? _textScaleFactor(Object? textScaling) {
if (textScaling case [[final num unscaled, final num scaled], ...]) {
return unscaled == 0 ? null : scaled / unscaled;
}
return null;
}
References
  1. Prioritize logic, performance on the UI thread, and architectural consistency. (link)

Comment on lines +187 to +192
Future<void> _overrideTextScale(double textScale) async {
await widget.controller.setTextScale(textScale);
if (mounted && _sliderTextScale == textScale) {
setState(() => _sliderTextScale = null);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

[CONCERN] Wrapping the call in a try-finally block ensures that _sliderTextScale is reset to null even if the service call fails. This prevents the slider from getting stuck at an invalid/failed value and allows it to snap back to the actual value reported by the app.

  Future<void> _overrideTextScale(double textScale) async {
    try {
      await widget.controller.setTextScale(textScale);
    } finally {
      if (mounted && _sliderTextScale == textScale) {
        setState(() => _sliderTextScale = null);
      }
    }
  }
References
  1. Prioritize logic, performance on the UI thread, and architectural consistency. (link)

A call that throws no longer keeps the calls after it from running, and
the future of a call that a hot restart interrupts now completes. A
metric that DevTools stops overriding is no longer set again after a hot
restart, and a restore that fails is tried again after the next one.

The page ignores text scaling tables without a valid first point, and
setTextScale asserts that its factor is finite and not negative. The
text scale label now reads "System Default", like the brightness
dropdown next to it.
After a hot restart, the client now restores the text scale, bold text,
screen reader and high contrast overrides that the app had, whoever set
them, rather than only the ones that this client set. So the page shows the
same overrides after the restart, also after DevTools reloads.

The fake extension parses writes with DebugViewMetricsOverride.fromJson,
like the app, and can hold calls until a test releases them, so the tests
of a hot restart during a call no longer poll.

The client docs also say to create one client per connection.
The client no longer restores the overrides after a hot restart, which
empties them, so the page shows them as off afterwards. Restoring them,
along with brightness, is left to a follow-up.

Also removes the Future.any that completed calls interrupted by a hot
restart, shortens the docs of private members, and simplifies the held
calls of the fake extension, which no test releases anymore.
The VM service never answers a call that is in flight when its isolate
exits, so the future that updateOverrides returned for such a call never
completed. The text scale slider shows the value it was dragged to until
that future completes, so after a hot restart it could keep showing a
text scale that the app no longer had. These futures now complete when
the main isolate changes, and when the client is disposed.

Also tests that the client reads the overrides of the new isolate after
a hot restart.
The switch is meant to show the semantics debugger, not to override
accessibleNavigation, which only changes how some widgets behave.
Flutter has no service extension for the semantics debugger yet, so
the switch goes back to the placeholder it was before this PR. It now
sits below the controls that the extension backs, so that their
"unavailable" tooltip does not cover it.
After a hot restart the client kept the overrides of the isolate that
exited, so the page showed them until the new isolate answered its read,
with the controls enabled if the app sat at a breakpoint by then or the
read failed. The client now empties its overrides when the main isolate
changes.

The test of the read after a hot restart now fills the registry of the
new isolate, because an empty one no longer shows that the client read
it.

Also documents that a write removes a change that app code made with
debugSetViewMetricsOverride, which the app does not report, and tests
that dispose completes the calls that the app has not answered.
A switch shows what the app reports, so while the app sat at a
breakpoint a tap looked ignored, and a second tap sent the same write
again. Like the text scale slider, a switch now shows its new value
until the write is done.

Also names an app that has not started yet in the tooltip of the
disabled controls, which also shows during a hot restart.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants