Created
April 6, 2026 12:00
-
-
Save phyowaikyaw-mobiledev/6ba07583f6c775892cc0748704d1dc73 to your computer and use it in GitHub Desktop.
Assignment 18 - Password Visibility Toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return const MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: PasswordScreen(), | |
| ); | |
| } | |
| } | |
| class PasswordScreen extends StatefulWidget { | |
| const PasswordScreen({super.key}); | |
| @override | |
| State<PasswordScreen> createState() => _PasswordScreenState(); | |
| } | |
| class _PasswordScreenState extends State<PasswordScreen> { | |
| bool _isPasswordHidden = true; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: const Text('Password Field'), | |
| backgroundColor: Colors.blueGrey, | |
| foregroundColor: Colors.white, | |
| ), | |
| body: Padding( | |
| padding: const EdgeInsets.all(24), | |
| child: TextField( | |
| obscureText: _isPasswordHidden, | |
| decoration: InputDecoration( | |
| labelText: 'Password', | |
| border: const OutlineInputBorder(), | |
| suffixIcon: IconButton( | |
| icon: Icon( | |
| _isPasswordHidden ? Icons.visibility : Icons.visibility_off, | |
| ), | |
| onPressed: () { | |
| setState(() { | |
| _isPasswordHidden = !_isPasswordHidden; | |
| }); | |
| }, | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment