Skip to content

Instantly share code, notes, and snippets.

@phyowaikyaw-mobiledev
Created April 6, 2026 12:00
Show Gist options
  • Select an option

  • Save phyowaikyaw-mobiledev/6ba07583f6c775892cc0748704d1dc73 to your computer and use it in GitHub Desktop.

Select an option

Save phyowaikyaw-mobiledev/6ba07583f6c775892cc0748704d1dc73 to your computer and use it in GitHub Desktop.
Assignment 18 - Password Visibility Toggle
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