Skip to content

TextFormField - changing obscureText with state has a bug #72825

@callawey

Description

@callawey

Steps to Reproduce

  1. Run flutter create bug.
  2. Update main.dart as below
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Bug'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _hidden = true;

  void _changeVisibility() {
    setState(() {
      _hidden = !_hidden;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          width: 300,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextFormField(
                obscureText: _hidden,
                decoration: InputDecoration(
                  contentPadding: const EdgeInsets.all(0),
                  prefixIcon: Icon(Icons.lock_outline),
                  border: const OutlineInputBorder(),
                  labelText: "labelText",
                  suffixIcon: GestureDetector(
                    onTap: () {
                      _changeVisibility();
                    },
                    child: Icon(_hidden ? Icons.visibility_off : Icons.visibility),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
  1. run application on your android device, type something to textfield, click eye icon to change obscureText to false. Now you can see your entry. hide them again. delete a few characters. write something else. Click again to see your entries. Now you cant see first a few characters, they are still obscure.

Expected results:
when its state changes, it must show all

bug-2020-12-22-224631.mp4

or hide all of the characters.

[√] Flutter (Channel beta, 1.24.0-10.2.pre, on Microsoft Windows [Version 10.0.19042.685], locale en-GB)
    • Flutter version 1.24.0-10.2.pre at D:\Flutter
    • Framework revision 022b333a08 (5 weeks ago), 2020-11-18 11:35:09 -0800
    • Engine revision 07c1eed46b
    • Dart version 2.12.0 (build 2.12.0-29.10.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at D:\Android\SDK
    • Platform android-30, build-tools 29.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code, 64-bit edition (version 1.52.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.17.0

[√] Connected device (1 available)
    • SM G960U1 (mobile) • 3054524d4a313498 • android-arm64 • Android 10 (API 29)

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions