obscureText parameter is used in TextField widget to automatically convert all the entered text into U+2022 BULLET characters. They look like bullet DOT inside Text Field widget. This parameter is mostly used to hide typed text inside Text Field like password typing. This would make the typing secure. obscureText cannot be set to null or empty you should have to pass Boolean true or false in it. So in this tutorial we would Set TextField Text Input type Password in Flutter using obscureText Android iOS example tutorial.
Contents in this project Set TextField Text Input type Password in Flutter using obscureText Android iOS Example:
1. Import material.dart package in your app’s main.dart file.
1 |
import 'package:flutter/material.dart'; |
2. Call our main class MyApp using void main runApp() function.
1 |
void main() => runApp(MyApp()); |
3. Create our main class named as MyApp extends with State less widget.
1 2 3 4 |
class MyApp extends StatelessWidget { } |
4. Create Scaffold widget with Center widget in Widget build area.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: ) ) ); } } |
5. Create a Container parent widget and Put the TextField widget inside it.
- obscureText: true : Hiding the typed text in Text Input widget.
1 2 3 4 5 6 7 8 9 10 11 |
Container( width: 300, child: TextField( decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Enter Password Here', ), autofocus: false, obscureText: true, ) ) |
6. Complete source code for main.dart file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Container( width: 300, child: TextField( decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Enter Password Here', ), autofocus: false, obscureText: true, ) ) ) ) ); } } |
Screenshots:
