Skip to content

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.  #141560

Closed

Description

@assemblyios

Steps to reproduce

  1. Use android device
    2.Add a TextField
    3.Switch to the password entry box
    4.Enter the maximum length and then switch to another place
    5.Found plaintext displayed

Original title: Android TextField reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor and text is clearly displayed in the password box

Expected results

The maximum length cannot be entered, and the plaintext cannot be displayed

Actual results

4.Enter the maximum length and then switch to another place
5.Found plaintext displayed

Code sample

Code sample
TextField(
        //文字默认小写
        textCapitalization: TextCapitalization.none,
        style: TextStyle(
          color: FColor.text33,
          fontSize: widget.fontSize ?? 18.fsp,
        ),
        //是否能够复制粘贴
        enableInteractiveSelection: true,
        focusNode: widget.focusNode,
        maxLength: 20,
        autofocus: false,
        controller: widget.controller,
        inputFormatters: [
          FilteringTextInputFormatter.deny(
              RegExp(r'[\u4e00-\u9fa5.·\u36c3\u4DAE]'))
        ],
        obscureText: hidePw,
        textInputAction: TextInputAction.done,
        keyboardType: TextInputType.visiblePassword,
        decoration: InputDecoration(
          icon: widget.needIcon
              ? SvgPicture.asset(
                  ImageAssets.accountIcLockSvg,
                )
              : null,
          focusedBorder: InputBorder.none,
          enabledBorder: InputBorder.none,
          isCollapsed: true,
          hintText: widget.hintText,
          hintStyle: TextStyle(
              color: FColor.textCC,
              fontSize: widget.fontSize ?? 18.fsp,
              fontWeight: FontWeightPlus.w400),
          counterText: '',
          suffixIconConstraints: const BoxConstraints(
            maxHeight: 24,
            maxWidth: 15 + 11 + 24,
          ),
          suffixIcon: Container(
            margin: const EdgeInsets.only(right: 15, left: 11),
            child: GestureDetector(
                onTap: () {
                  setState(() {
                    hidePw = !hidePw;
                  });
                },
                child: Icon(
                  hidePw ? IconAssets.closeEye : Icons.remove_red_eye,
                  color: FColor.hintText,
                )),
          ),
        ),
      )

Screenshots or Video

Screenshots / Video demonstration
20ce162c8834da411396f1f307aba6cd.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.1.1 23B81 darwin-arm64, locale
    zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.85.1)
[✓] Connected device (5 available)
[✓] Network resources

Activity

  1. changed the title [-]reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor is clearly displayed in the password box[/-] [+]Android reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor is clearly displayed in the password box[/+] on Jan 15, 2024
  2. changed the title [-]Android reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor is clearly displayed in the password box[/-] [+]Android TextField reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor is clearly displayed in the password box[/+] on Jan 15, 2024
  3. changed the title [-]Android TextField reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor is clearly displayed in the password box[/-] [+]Android TextField reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor and text is clearly displayed in the password box[/+] on Jan 15, 2024
  4. added
    in triage
    on Jan 15, 2024
  5. dam-ease commented on Jan 15, 2024

    @dam-ease

    Thanks for filing this @assemblyios.
    I can reproduce this on the latest master and stable channels.

    Screen record

    untitled.webm

    Some observations during triage:

    • This occurs only when obscureText:true.
    • Using onChanged property to print out changes, although the text shows on the phone screen as being input, no change takes place here, the number of text remains as the maximum and onChanged doesn't print out any change.
    • Tested on iOS and couldn't reproduce, this seems peculiar to only Android.
    Code Sample

    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          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> {
      FocusNode focusNode = FocusNode();
      TextEditingController controller = TextEditingController();
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              backgroundColor: Theme.of(context).colorScheme.inversePrimary,
              title: Text(widget.title),
            ),
            drawer: Container(
              width: 150,
              color: Colors.blue,
              child: const TextField(),
            ),
            body: TextField(
              textCapitalization: TextCapitalization.none,
              enableInteractiveSelection: true,
              focusNode: focusNode,
              maxLength: 20,
              onChanged: (val) {
                print(val);
              },
              autofocus: false,
              controller: controller,
              inputFormatters: [
                FilteringTextInputFormatter.deny(
                    RegExp(r'[\u4e00-\u9fa5.·\u36c3\u4DAE]'))
              ],
              obscureText: true,
              textInputAction: TextInputAction.done,
              keyboardType: TextInputType.visiblePassword,
            ));
      }
    }
    

    stable, master flutter doctor -v

    [!] Flutter (Channel stable, 3.16.7, on macOS 14.2.1 23C71 darwin-arm64, locale
        en-NG)
        • Flutter version 3.16.7 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        ! Warning: `dart` on your path resolves to
          /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/damilolaalimi/sdks/flutter.
          Consider adding /Users/damilolaalimi/sdks/flutter/bin to the front of your
          path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ef1af02aea (3 days ago), 2024-01-11 15:19:26 -0600
        • Engine revision 4a585b7929
        • Dart version 3.2.4
        • DevTools version 2.28.5
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C65
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
          Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build
          17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.85.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (4 available)
        • Damilola’s iPhone (mobile) • 00008110-001964480AE1801E            • ios
          • iOS 17.1.1 21B91
        • iPhone 15 (mobile)         • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)            • macos                                •
          darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)               • chrome                               •
          web-javascript • Google Chrome 120.0.6099.216
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    
    [!] Flutter (Channel master, 3.19.0-4.0.pre.42, on macOS 14.2.1 23C71 darwin-arm64, locale en-NG)
        • Flutter version 3.19.0-4.0.pre.42 on channel master at /Users/damilolaalimi/fvm/versions/master
        ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 5931b4f21d (5 hours ago), 2024-01-11 20:42:07 -0800
        • Engine revision 44a0a6ee4d
        • Dart version 3.4.0 (build 3.4.0-16.0.dev)
        • DevTools version 2.31.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C65
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.85.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (6 available)
        • sdk gphone64 arm64 (mobile)         • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)          • 00008110-001964480AE1801E            • ios            • iOS 17.1.1 21B91
        • iPhone SE (3rd generation) (mobile) • 2512805F-1CB0-4FAF-89B3-4E9EC54CD6D2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • iPhone 15 (mobile)                  • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)                     • macos                                • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 120.0.6099.216
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    

  6. added
    a: text input
    platform-android
    engine
    has reproducible steps
    team-android
    found in release: 3.16
    found in release: 3.18
    and removed
    in triage
    on Jan 15, 2024
  7. assemblyios commented on Jan 16, 2024

    @assemblyios
    Author

    Thanks for filing this @assemblyios. I can reproduce this on the latest master and stable channels.

    Screen record
    Some observations during triage:

    • This occurs only when obscureText:true.
    • Using onChanged property to print out changes, although the text shows on the phone screen as being input, no change takes place here, the number of text remains as the maximum and onChanged doesn't print out any change.
    • Tested on iOS and couldn't reproduce, this seems peculiar to only Android.

    Code Sample
    stable, master flutter doctor -v

    Yes, that's what you described. Thank you

  8. changed the title [-]Android TextField reaches the maximum password value, switching to any position and entering a new character again should not take effect, but the location cursor and text is clearly displayed in the password box[/-] [+]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. [/+] on Jan 18, 2024
  9. added
    P2
    framework
    triaged-android
    on Jan 18, 2024
  10. added a commit that references this issue on May 14, 2026
  11. self-assigned this
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2a: text inputenginefound in release: 3.16found in release: 3.18frameworkhas reproducible stepsplatform-androidteam-androidtriaged-android

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions