Steps to reproduce
Run the sample app on a mobile device
Type some text in the password field and immediately press the Show Text button twice
Expected results
When TextField.obscureText is toggled quickly from true → false → true, all characters should be obscured.
Actual results
When TextField.obscureText is toggled quickly from true → false → true, the most recently entered character is briefly visible.
Code sample
Code sample
import 'package:flutter/material.dart' ;
void main () => runApp (const MyApp ());
class MyApp extends StatelessWidget {
const MyApp ({super .key});
@override
Widget build (BuildContext context) {
return MaterialApp (
home: Scaffold (
body: Center (
child: Padding (
padding: .all (20.0 ),
child: PasswordToggleField (),
),
),
),
);
}
}
class PasswordToggleField extends StatefulWidget {
const PasswordToggleField ({super .key});
@override
State <PasswordToggleField > createState () => _PasswordToggleFieldState ();
}
class _PasswordToggleFieldState extends State <PasswordToggleField > {
bool _isObscured = true ;
@override
Widget build (BuildContext context) {
return Column (
mainAxisSize: .min,
spacing: 20 ,
children: [
TextField (
obscureText: _isObscured,
decoration: const InputDecoration (
border: OutlineInputBorder (),
labelText: 'Password' ,
),
),
ElevatedButton (
onPressed: () {
// 3. Toggle the state and rebuild the UI
setState (() {
_isObscured = ! _isObscured;
});
},
child: Text (_isObscured ? 'Show Text' : 'Hide Text' ),
),
],
);
}
}
Screenshots or Video
Screenshots / Video demonstration
obscureText_2.mov
Logs
N/A
Flutter Doctor output
N/A
Steps to reproduce
Show Textbutton twiceExpected results
When
TextField.obscureTextis toggled quickly from true → false → true, all characters should be obscured.Actual results
When
TextField.obscureTextis toggled quickly from true → false → true, the most recently entered character is briefly visible.Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
obscureText_2.mov
Logs
N/A
Flutter Doctor output
N/A