Skip to content

Keep last character obscured when toggling obscureText#183488

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
TrangLeQuynh:obscureTextFix
Apr 6, 2026
Merged

Keep last character obscured when toggling obscureText#183488
auto-submit[bot] merged 1 commit into
flutter:masterfrom
TrangLeQuynh:obscureTextFix

Conversation

@TrangLeQuynh

@TrangLeQuynh TrangLeQuynh commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

…perty toggle on or off

Summary

When obscureText is toggled quickly from true → false → true, the most recently entered character is shown in an obscured text field.

Fixes #184483

Steps to restore

  1. Create a TextField with obscureText = true.

  2. Quickly type some text.

  3. Toggle obscureText to false.

  4. Immediately toggle it back to true.

  5. Observe the displayed text.

Note: This behavior occurs when the operations are performed quickly (≤ ~1500 ms), due to defaults:

// The time it takes for the cursor to fade from fully opaque to fully
// transparent and vice versa. A full cursor blink, from transparent to opaque
// to transparent, is twice this duration.
const Duration _kCursorBlinkHalfPeriod = Duration(milliseconds: 500);

// Number of cursor ticks during which the most recently entered character
// is shown in an obscured text field.
const int _kObscureShowLatestCharCursorTicks = 3;

Actual Result

The most recently entered character may still be visible briefly after obscureText is set back to true

obscureText_1.mov

Expect result

When obscureText is updated to true, all characters should be immediately obscured, regardless of previously revealed characters.

obscureText_2.mov

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@google-cla

google-cla Bot commented Mar 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 Mar 11, 2026

@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 addresses an issue where the last character of an obscured text field could be briefly revealed when the obscureText property is toggled. The change resets a timer responsible for showing the last character whenever obscureText changes. My feedback includes a suggestion to improve a code comment for clarity.

Note: Security Review is unavailable for this PR.

Comment on lines +3409 to +3410
//reset to prevent the last character in obscure text
_obscureShowCharTicksPending = 0;

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

This comment could be more descriptive and adhere to the Dart style guide by starting with a capital letter. A clearer comment would explain why _obscureShowCharTicksPending is reset when obscureText changes.

// When `obscureText` is toggled, we should not be in the middle of revealing a character.
_obscureShowCharTicksPending = 0;
References
  1. The repository style guide defers to 'Effective Dart: Style' (line 20), which recommends capitalizing comments like sentences. (link)
  2. The repository style guide states that documentation should be useful and explain the 'why' and the 'how' (line 55). A more descriptive comment would improve readability. (link)

@Renzo-Olivares Renzo-Olivares requested review from Renzo-Olivares and removed request for Renzo-Olivares March 12, 2026 20:31
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

@TrangLeQuynh thank you for the contribution! Before moving forward with this PR you will need to sign the CLA and write a test to verify that the expected behavior works after the change.

@TrangLeQuynh TrangLeQuynh force-pushed the obscureTextFix branch 2 times, most recently from cceccf4 to e23fac8 Compare March 13, 2026 14:59
@TrangLeQuynh

Copy link
Copy Markdown
Contributor Author

@Renzo-Olivares Thanks for the feedback. I have now signed the CLA and added the test to verify the expected behavior. Please take another look when you have a moment.

@Renzo-Olivares Renzo-Olivares self-requested a review March 13, 2026 19:18

@Renzo-Olivares Renzo-Olivares 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.

Hi @TrangLeQuynh, thank you for the contribution! Left a few comments.

Comment thread packages/flutter/test_fixes/widgets/editable_text_fix.dart Outdated
Comment thread packages/flutter/test_fixes/widgets/editable_text_fix.dart Outdated
Comment thread packages/flutter/test_fixes/widgets/editable_text_fix.dart Outdated
Comment thread packages/flutter/test_fixes/widgets/editable_text_fix.dart Outdated
Comment thread packages/flutter/test_fixes/widgets/editable_text_fix.dart Outdated
Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
@@ -3406,6 +3406,8 @@ class EditableTextState extends State<EditableText>
if (_hasInputConnection) {
if (oldWidget.obscureText != widget.obscureText ||
oldWidget.keyboardType != widget.keyboardType) {

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.

I think it sounds reasonable to reset this last obscure character when the keyboard type changes but curious to hear others thoughts. In triage we discussed only resetting when obscureText changes.

@TrangLeQuynh TrangLeQuynh force-pushed the obscureTextFix branch 4 times, most recently from 1a8b16d to a1b6f75 Compare March 23, 2026 04:30
@TrangLeQuynh

TrangLeQuynh commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@Renzo-Olivares I have updated according to your comment.

On non-mobile platforms, the last character of the obscure text is not briefly revealed. Therefore, this bug only occurs on mobile, and tests need to explicitly cover mobile platforms(iOS, Android, Fuchsia) instead of relying on the default.

Comment thread packages/flutter/test/widgets/editable_text_test.dart
Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated

@Renzo-Olivares Renzo-Olivares 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.

LGTM pending my last nit

Renzo-Olivares
Renzo-Olivares previously approved these changes Mar 26, 2026

@Renzo-Olivares Renzo-Olivares 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.

LGTM, thank you for the contribution @TrangLeQuynh!

@justinmc justinmc requested a review from loic-sharma March 26, 2026 20:28
@loic-sharma loic-sharma changed the title [FIX] Prevent the last character in obscure text when obscureText pro… Keep last character obscured when toggling obscureText Mar 30, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Mar 30, 2026
@loic-sharma

loic-sharma commented Mar 30, 2026

Copy link
Copy Markdown
Member

@TrangLeQuynh it looks like this comment hasn't been addressed yet: #183488 (comment)

Also it looks like there's some analysis errors: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8685868144703014273/+/u/run_analyzer_benchmark/stdout

[2026-03-30 15:02:03.924711] [STDOUT] stdout:    info • Omit the type annotation on a local variable when the type is obvious • packages/flutter/lib/src/widgets/editable_text.dart:3407:13 • omit_obvious_local_variable_types
[2026-03-30 15:02:03.924775] [STDOUT] stdout:    info • Omit the type annotation on a local variable when the type is obvious • packages/flutter/test/widgets/editable_text_test.dart:17916:7 • omit_obvious_local_variable_types

@loic-sharma loic-sharma added the CICD Run CI/CD label Apr 3, 2026

@loic-sharma loic-sharma 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.

Re-LGTM!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 6, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Apr 6, 2026
Merged via the queue into flutter:master with commit 7f3269b Apr 6, 2026
79 of 80 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 7, 2026
flutter/flutter@9cd60b5...a0924c7

2026-04-07 dacoharkes@google.com Reland "[data_assets] Cleanup tests" (flutter/flutter#184714)
2026-04-07 matt.kosarek@canonical.com Use the WindowRegistry in the multiple_windows example app (flutter/flutter#184579)
2026-04-07 15619084+vashworth@users.noreply.github.com Introduce command to build a swift package for SwiftPM add to app integration (flutter/flutter#184660)
2026-04-07 sigurdm@google.com Have `flutter create` create a pubspec.lock to ensure pinned versions are being used. (flutter/flutter#175352)
2026-04-07 59215665+davidhicks980@users.noreply.github.com [widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter/flutter#182357)
2026-04-07 rmolivares@renzo-olivares.dev `WindowsPlugin` should not crash when ffiPlugin enabled (flutter/flutter#184695)
2026-04-06 97480502+b-luk@users.noreply.github.com Use full goto.google.com hostname for go/ links (flutter/flutter#184679)
2026-04-06 34871572+gmackall@users.noreply.github.com Apply rect clipping to surface views (flutter/flutter#184471)
2026-04-06 jhy03261997@gmail.com [A11y] Allow percentage strings like "50%" as `SemanticsValue` for `ProgressIndicator` (flutter/flutter#183670)
2026-04-06 louisehsu@google.com Fix invisible accessibility element before scroll view (flutter/flutter#184155)
2026-04-06 engine-flutter-autoroll@skia.org Roll Skia from 163dfdf500c7 to e264d870a380 (2 revisions) (flutter/flutter#184674)
2026-04-06 54688429+TrangLeQuynh@users.noreply.github.com Keep last character obscured when toggling obscureText (flutter/flutter#183488)
2026-04-06 15619084+vashworth@users.noreply.github.com Parse scheme file with XML parser for SwiftPM migrator (flutter/flutter#184525)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com 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
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
…perty toggle on or off


### Summary
When `obscureText` is toggled quickly from true → false → true, the most
recently entered character is shown in an obscured text field.

Fixes flutter#184483

### Steps to restore

1. Create a TextField with `obscureText = true`.

2. Quickly type some text.

3. Toggle `obscureText` to **false**.

4. Immediately toggle it back to **true**.

5. Observe the displayed text.

> Note: This behavior occurs when the operations are performed quickly
(≤ ~1500 ms), due to defaults:
>
> ```dart
> // The time it takes for the cursor to fade from fully opaque to fully
>// transparent and vice versa. A full cursor blink, from transparent to
opaque
>// to transparent, is twice this duration.
>const Duration _kCursorBlinkHalfPeriod = Duration(milliseconds: 500);
>
>// Number of cursor ticks during which the most recently entered
character
>// is shown in an obscured text field.
>const int _kObscureShowLatestCharCursorTicks = 3;
> ```


### Actual Result

The most recently entered character may still be visible briefly after
`obscureText` is set back to true



https://github.com/user-attachments/assets/94d2ba56-c551-4385-8f88-3dd746c8dc09



### Expect result

When `obscureText` is updated to true, all characters should be
immediately obscured, regardless of previously revealed characters.



https://github.com/user-attachments/assets/992e0473-059c-4c7a-a1b1-8ca6bf222538
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11463)

flutter/flutter@9cd60b5...a0924c7

2026-04-07 dacoharkes@google.com Reland "[data_assets] Cleanup tests" (flutter/flutter#184714)
2026-04-07 matt.kosarek@canonical.com Use the WindowRegistry in the multiple_windows example app (flutter/flutter#184579)
2026-04-07 15619084+vashworth@users.noreply.github.com Introduce command to build a swift package for SwiftPM add to app integration (flutter/flutter#184660)
2026-04-07 sigurdm@google.com Have `flutter create` create a pubspec.lock to ensure pinned versions are being used. (flutter/flutter#175352)
2026-04-07 59215665+davidhicks980@users.noreply.github.com [widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter/flutter#182357)
2026-04-07 rmolivares@renzo-olivares.dev `WindowsPlugin` should not crash when ffiPlugin enabled (flutter/flutter#184695)
2026-04-06 97480502+b-luk@users.noreply.github.com Use full goto.google.com hostname for go/ links (flutter/flutter#184679)
2026-04-06 34871572+gmackall@users.noreply.github.com Apply rect clipping to surface views (flutter/flutter#184471)
2026-04-06 jhy03261997@gmail.com [A11y] Allow percentage strings like "50%" as `SemanticsValue` for `ProgressIndicator` (flutter/flutter#183670)
2026-04-06 louisehsu@google.com Fix invisible accessibility element before scroll view (flutter/flutter#184155)
2026-04-06 engine-flutter-autoroll@skia.org Roll Skia from 163dfdf500c7 to e264d870a380 (2 revisions) (flutter/flutter#184674)
2026-04-06 54688429+TrangLeQuynh@users.noreply.github.com Keep last character obscured when toggling obscureText (flutter/flutter#183488)
2026-04-06 15619084+vashworth@users.noreply.github.com Parse scheme file with XML parser for SwiftPM migrator (flutter/flutter#184525)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com 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.

Toggling TextField.obscureText can show the last character

4 participants