Skip to content

Keyboard Hints Disappear and Reappear When Toggling Password Visibility in Flutter TextField #162582

@mathis6787

Description

@mathis6787

Steps to reproduce

When toggling the visibility of a password field in a Flutter app, the keyboard hints (e.g., autofill suggestions, password manager hints) disappear and reappear. This issue occurs only on iOS 18 on emulator and on physical device.

Create a TextField with obscureText set to true for password input.

Add an IconButton to toggle obscureText between true and false.

Run the app on an iOS 18 device or simulator.

Focus on the password field to bring up the keyboard.

Tap the visibility icon to toggle password visibility.

Observe the keyboard hints (e.g., autofill suggestions) disappearing and reappearing.

Expected results

The keyboard hints (e.g., autofill suggestions, password manager hints) should remain stable and not disappear when toggling password visibility.

Actual results

The keyboard hints disappear and reappear when toggling password visibility, causing a flickering effect and disrupting the user experience.

Code sample

Code sample
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Password Field Bug')),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: PasswordField(),
        ),
      ),
    );
  }
}

class PasswordField extends StatefulWidget {
  @override
  _PasswordFieldState createState() => _PasswordFieldState();
}

class _PasswordFieldState extends State<PasswordField> {
  bool _isObscured = true;

  void _toggleVisibility() {
    setState(() {
      _isObscured = !_isObscured;
    });
  }

  @override
  Widget build(BuildContext context) {
    return TextField(
      obscureText: _isObscured,
      decoration: InputDecoration(
        hintText: "Enter your password",
        border: OutlineInputBorder(),
        suffixIcon: IconButton(
          icon: Icon(_isObscured ? Icons.visibility_off : Icons.visibility),
          onPressed: _toggleVisibility,
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
flutter doctor -v
r -v
[✓] Flutter (Channel stable, 3.27.3, on macOS 15.3 24D60 darwin-arm64,
    locale fr-CA)
    • Flutter version 3.27.3 on channel stable at
      /Users/mathisdesmeules/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (12 days ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
    • Android SDK at /Users/mathisdesmeules/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • ANDROID_SDK_ROOT = /Users/mathisdesmeules/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • 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.10+0-17.0.10b1087.21-11572160)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1.2)
    • IntelliJ at /Users/mathisdesmeules/Applications/IntelliJ IDEA
      Ultimate.app
    • 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

[✓] VS Code (version 1.96.4)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available)
    • iPhone 16 (mobile)              • 286DDF34-0024-4D50-8DDA-FD58730D5085
      • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-2
      (simulator)
    • macOS (desktop)                 • macos
      • darwin-arm64   • macOS 15.3 24D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad
      • darwin         • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome
      • web-javascript • Google Chrome 132.0.6834.160

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemse: OS-version specificAffects only some versions of the relevant operating systemfound in release: 3.27Found to occur in 3.27found in release: 3.29Found to occur in 3.29frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyteam-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