Skip to content

Do not reveal obscured character when input is rejected by inputFormatters - #195022

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
okorohelijah:fix-141560-obscure-text-maxlength
Nov 16, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
okorohelijah:fix-141560-obscure-text-maxlength

Conversation

@okorohelijah

@okorohelijah okorohelijah commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #141560

Description

When EditableText.obscureText is true, EditableTextState.updateEditingValue decided whether to briefly reveal the "newly typed" character (value.text.length == _value.text.length + 1) and recorded its index before running _formatAndSetValue.

When an inputFormatter (such as LengthLimitingTextInputFormatter once maxLength is reached) rejected the newly inserted character, _value stayed unchanged, yet _obscureShowCharTicksPending and _obscureLatestCharIndex were still set. The reveal was then painted by the next rebuild (for example a caret move), showing the existing character at the caret in plain text. On Android this is the default behaviour of TextField(maxLength: …, obscureText: true) because maxLength defaults to MaxLengthEnforcement.enforced there.

This change moves _formatAndSetValue before the reveal decision and only reveals when both:

  1. exactly one character was added by the platform (value.text.length == oldValue.text.length + 1), and
  2. the formatted value kept that character (_value.text.length == value.text.length).

If a character was still revealed from a previous keystroke and the new input is rejected, the state is cleared with a rebuild so the character is re-obscured immediately. A rejected edit leaves the controller value unchanged, so nothing else would trigger that rebuild.

This follows the direction given on the earlier attempt #144929: fix the logic in updateEditingValue rather than adding maxLength to EditableText's public API (#144929 (comment)).

Behaviour note: the reveal decision now looks at the formatted value. A formatter that accepts a keystroke but changes the text length (for example one that inserts separators) no longer reveals a character; a same-length transform still reveals the transformed character. Previously such cases revealed whatever character sat at the old caret index.

Verified on a device

Pixel 9 Pro emulator, Android 17 (API 37), TextField(obscureText: true, maxLength: 5): type abcde, move the caret to position 2, type z, press →.

Before (master) After (this PR)
Before: the existing character at the caret is shown in plain text after the caret moves After: the field stays obscured

Recordings as MP4: before, after.

Pre-launch 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 and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • 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.
  • All existing and new tests are passing.

@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 Oct 22, 2026
@okorohelijah
okorohelijah marked this pull request as ready for review October 26, 2026 09:44

@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 updates EditableTextState in editable_text.dart to ensure obscured characters are not incorrectly revealed when input is rejected or modified by inputFormatters. It captures the text editing value prior to formatting, refines the conditions for revealing obscured input, and triggers a state update to immediately re-obscure characters if pending ticks are reset. Two regression tests are also added to editable_text_test.dart to validate these changes. There are no review comments, and I have no feedback to provide.

@okorohelijah okorohelijah added the CICD Run CI/CD label Oct 26, 2026
@okorohelijah
okorohelijah requested review from a team and gmackall and removed request for a team October 26, 2026 21:10

@gmackall gmackall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this mostly LGTM, but it's interacting poorly with what I think is an independent bug:

Moving _formatAndSetValue before setting _obscureShowCharTicksPending causes the last typed character to stay revealed indefinitely when !_showBlinkingCursor (for example, when showCursor: false).

This happens because:

  1. _formatAndSetValue synchronously calls _didChangeTextEditingValue → _startOrStopCursorTimerIfNeeded → _stopCursorBlink(resetCharTicks: true), which previously reset _obscureShowCharTicksPending = 0 when !_showBlinkingCursor.
  2. Now that _obscureShowCharTicksPending is set after _formatAndSetValue, it stays at 3 because _cursorTimer is not running when !_showBlinkingCursor, and _onCursorTick never fires to decrement it.

Gating revealObscuredInput on _showBlinkingCursor as well should fix this for now, though I think the real bug here is that obscure text should have its own timer (independent of the blinking cursor timer) (but that should be tackled in its own pr probably). Normally I'd not ask for a workaround for what looks to me like an independent bug, but the particular interaction here (the text staying unhidden permanently) is unfortunate enough that it would be good to work around (at least that's my opinion, but I'm pretty unfamiliar with the code here. Might be good to get review from the framework team).

You can see this with the minimal app:

import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(child: TextField(obscureText: true, showCursor: false)),
      ),
    );
  }
}

where the obscured text doesn't go away:

Image

@Renzo-Olivares

Renzo-Olivares commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Hello from framework triage: Is this ready to land?

@okorohelijah okorohelijah added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
@auto-submit

auto-submit Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/195022, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@okorohelijah okorohelijah added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 16, 2026
Merged via the queue into flutter:master with commit 581056a Nov 16, 2026
32 of 33 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 17, 2026
flutter/flutter@d8bd864...2f09f96

2026-11-17 [email protected] Analyze every flutter create template, and fix the package_ffi lint (flutter/flutter#196165)
2026-11-17 [email protected] Roll Dart SDK from 50debf3c9757 to 26e38955d9d4 (3 revisions) (flutter/flutter#196772)
2026-11-17 [email protected] Manual roll ICU from b09986242cfb to d3c612f44146 (1 revision) (flutter/flutter#196713)
2026-11-17 [email protected] Roll Skia from 4f6b3a8d8565 to 503a380ebecc (19 revisions) (flutter/flutter#196768)
2026-11-17 [email protected] iOS: Don't mock UIView animations in keyboard spring animation test (flutter/flutter#196755)
2026-11-17 [email protected] [flutter_tools] Preserve index.html across --web-content-hash transitions (flutter/flutter#196491)
2026-11-17 [email protected] Fix TextStyle background color fade-out when lerping to null (flutter/flutter#196153)
2026-11-17 [email protected] Update desktop engine TESTOWNERS (flutter/flutter#196732)
2026-11-17 [email protected] [flutter_tools] Do not copy app-only build type properties onto library plugins (flutter/flutter#196692)
2026-11-17 [email protected] [flutter_tools] Remove service and runner ambient context getters (flutter/flutter#196571)
2026-11-17 [email protected] Bump customer tests (flutter/flutter#196740)
2026-11-17 [email protected] Take customer_testing_flame out of bringup (flutter/flutter#196570)
2026-11-17 [email protected] [devicelab] Read AssetManifest.bin from the APK in flavors_test (flutter/flutter#196736)
2026-11-17 [email protected] [flutter_tools] Fix flaky tool_tests_general by moving spawnUri tests to integration shard (flutter/flutter#195999)
2026-11-17 [email protected] Roll Dart SDK from 3e069c6fdbde to 50debf3c9757 (2 revisions) (flutter/flutter#196706)
2026-11-16 [email protected] [web] Record build finish synchronously in renderScene and fix dropped frame timings (flutter/flutter#195947)
2026-11-16 [email protected] Do not reveal obscured character when input is rejected by inputFormatters (flutter/flutter#195022)
2026-11-16 [email protected] Cla draft follow up: add waiting for response (flutter/flutter#196686)
2026-11-16 [email protected] Roll pub packages (flutter/flutter#196684)
2026-11-16 [email protected] Roll Packages from 015df97 to 4c6a7d3 (8 revisions) (flutter/flutter#196681)
2026-11-16 [email protected] Skip Vulkan impeller_unittests on macOS (flutter/flutter#196282)
2026-11-16 [email protected] Move the task runners out of Flutter Engine (flutter/flutter#196267)
2026-11-16 [email protected] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… (flutter/flutter#196465)
2026-11-16 [email protected] iOS: Add Obj-C model for platform view composition params (flutter/flutter#196498)
2026-11-16 [email protected] [Windows] Normalize Shift key messages with a non-standard scan code (flutter/flutter#193675)
2026-11-16 [email protected] Roll Skia from 118eaff3deb4 to 4f6b3a8d8565 (3 revisions) (flutter/flutter#196672)
2026-11-16 [email protected] Roll Dart SDK from c91e8b6674e2 to 3e069c6fdbde (4 revisions) (flutter/flutter#196669)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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 CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter text field (on android) shows plain text character when max char limit reached and user attempts to insert in the middle of the string.

4 participants