Skip to content

Add password (numeric-password) variation to TextInputType.numberWithOptions #190204

Closed

Description

@AlexV525

Use case

Flutter already exposes the text-class password variations through TextInputType.visiblePassword (added in #36695, closing #31738), which maps to Android's TYPE_TEXT_VARIATION_VISIBLE_PASSWORD.

The numeric-class counterpart — TYPE_NUMBER_VARIATION_PASSWORD — has no representation in TextInputType. TextInputType.numberWithOptions currently exposes only signed and decimal, so there is no way for a Flutter field to declare itself as a numeric-password input to the platform / IME. The engine's Android TextInputPlugin NUMBER branch never sets TYPE_NUMBER_VARIATION_PASSWORD, and — correctly — obscureText is not used to derive it, because visual obscuring is a Flutter rendering concern independent of the platform input classification.

Concretely, a native Android field declared as

inputType = TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD  // 2 | 16 = 18

is also the canonical form documented by the platform as android:inputType="numberPassword" — i.e. Android itself treats this combination as a first-class, named input type. It cannot be produced from Flutter public API today.

Real-world numeric password fields in native apps (banking PIN entry, OTP screens) are routinely built with inputType == 18; a Flutter port has to settle for inputType == 2 and give up any platform-level cues tied to the numeric-password classification (IME candidate policy, contextual suggestions, form-manager heuristics, per-IME learning behavior).

Why not use existing knobs

  • obscureText: true — wrong tool. It masks the glyphs Flutter renders; consumers that draw their own cells (custom PIN widgets) need the raw text visible while still declaring the field as numeric-password to the platform.
  • TextInputType.visiblePassword — text class, not numeric; brings up a full alphanumeric keyboard.
  • AutofillHints / enableIMEPersonalizedLearning — orthogonal signals (autofill hints and imeOptions respectively); they don't set inputType.
  • A pub.dev package — not viable: the inputType mapping lives in the engine's TextInputPlugin and is not pluggable from Dart.

Proposal

Add a password parameter to TextInputType.numberWithOptions, symmetric to the visiblePassword precedent:

const TextInputType.numberWithOptions({
  this.signed = false,
  this.decimal = false,
  this.password = false,   // NEW
});

Default false — construction of existing TextInputType.number and TextInputType.numberWithOptions(...) is byte-for-byte unchanged. toJson, operator ==, hashCode, and toString are updated to include the new field.

Serialization — additive JSON field; older engines that don't parse it fall back to today's behavior:

{
  "name": "TextInputType.number",
  "signed": false,
  "decimal": false,
  "password": true
}

Platform mapping

  • Android (TextInputPlugin.inputTypeFromTextInputType, NUMBER branch):

    int textType = InputType.TYPE_CLASS_NUMBER;
    if (type.isSigned)   textType |= InputType.TYPE_NUMBER_FLAG_SIGNED;
    if (type.isDecimal)  textType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
    if (type.isPassword) textType |= InputType.TYPE_NUMBER_VARIATION_PASSWORD;

    obscureText remains orthogonal — it neither implies nor is implied by TYPE_NUMBER_VARIATION_PASSWORD. This preserves behavior for every existing keyboardType: number + obscureText: true field.

  • iOS — iOS traits are independent, not a bit field. password: true is a no-op for UIKeyboardType (stays .numberPad) and does not set isSecureTextEntry. obscureText continues to drive masking; AutofillHints.oneTimeCode continues to drive .oneTimeCode.

  • Web — inputmode="numeric" unchanged; HTML type="password" continues to be driven by obscureText.

  • Windows / macOS / Linux — no-op in v1, documented.

Backward compatibility

  • Additive; default false; no behavior change for existing callers.
  • JSON is additive.
  • No change to obscureText, AutofillHints, or enableIMEPersonalizedLearning semantics.

Docs will state explicitly: password: true declares the platform input classification only. It does not obscure Flutter-rendered glyphs — use obscureText for that. It is currently a no-op on iOS / web / desktop.

Tests

  • Framework: default value, toJson, ==, hashCode, toString, unchanged signed/decimal behavior.
  • Android engine inputType matrix: number→2, number+password→18, number+signed→4098, number+decimal→8194, JSON without password→2.
  • Orthogonality: obscureText alone doesn't set the variation; enableIMEPersonalizedLearning: false still only touches imeOptions; AutofillHints.oneTimeCode still only touches autofill hints.

Landing order — per Tree Hygiene, engine JSON parsing + Android mapping first, framework field once the engine revision is available; happy to split PRs that way.

Filing this issue before sending a PR to align on API shape. Precedent: #36695 / #31738.

References:

Activity

  1. AlexV525 commented on Jul 29, 2026

    @AlexV525
    MemberAuthor

    Proposed implementation checklist

    • Embedding — Android: add isPassword to TextInputChannel.InputType, parse json.optBoolean("password", false), and OR in TYPE_NUMBER_VARIATION_PASSWORD in TextInputPlugin's NUMBER branch; unit-test the inputType matrix (number→2, +password→18, +signed→4098, +decimal→8194, JSON without password→2) and orthogonality vs obscureText / imeOptions / autofill hints. iOS / Web / desktop: no code change; assert in tests that iOS keeps .numberPad and does not set isSecureTextEntry, Web keeps inputmode="numeric", desktop is documented no-op. [Android] Add numeric-password variation to TextInputType (embedding) #190207
    • Framework — packages/flutter/lib/src/services/text_input.dart: add password param (default false) to TextInputType.numberWithOptions; update toJson, operator ==, hashCode, toString, and dartdoc (explicitly: platform input classification only, does not obscure rendered glyphs, no-op on iOS / web / desktop); tests cover default value, toJson, ==, hashCode, toString, unchanged signed/decimal behavior. Add numeric-password variation to TextInputType.numberWithOptions #190637
  2. added
    a: text inputEntering text in a text field or keyboard related problems
    c: proposalA detailed proposal for a change to Flutter
    fyi-androidFor the attention of Android platform team
    on Jul 29, 2026
  3. added
    P1High-priority issues at the top of the work list
    on Jul 30, 2026
  4. Renzo-Olivares commented on Jul 30, 2026

    @Renzo-Olivares
    Contributor

    Hi @AlexV525 I assigned this to you since it looks like you are already working on it. Feel free to unassign if this is not the case. Overall this looks like a reasonable add to the framework since it is not currently possible to achieve the desired secure functionality of the IME without the correct TextInputType configuration.

  5. Renzo-Olivares commented on Aug 27, 2026

    @Renzo-Olivares
    Contributor

    Hi @AlexV525, can we declare victory on this now that the engine/framework prs have been merged?

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 27, 2026
  7. AlexV525 commented on Aug 28, 2026

    @AlexV525
    MemberAuthor

    Hi @AlexV525, can we declare victory on this now that the engine/framework prs have been merged?

    Yes! I've just checked this by producing new APKs and verified on devices. All of the work is valid. So the goal is complete. 🥇

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 29, 2026
  9. github-actions commented on Sep 12, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: proposalA detailed proposal for a change to Flutterfyi-androidFor the attention of Android platform teamteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions