import 'package:flutter/material.dart'; import 'messenger.dart'; void main() { runApp(const MaterialApp( debugShowCheckedModeBanner: false, home: LoginScreen())); } class LoginScreen extends StatefulWidget { const LoginScreen({Key? key}) : super(key: key); @override State createState() => _LoginScreenState(); } class _LoginScreenState extends State { final myController1 = TextEditingController(); final myController2 = TextEditingController(); bool isObscureText = true; bool showCredentials = false; @override void dispose() { myController1.dispose(); myController2.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final height = MediaQuery.of(context).size.height; return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Column( children: [ SizedBox(height: height * 1 / 5), TextField( controller: myController1, decoration: const InputDecoration( labelText: 'Username', focusedBorder: OutlineInputBorder( borderSide: BorderSide( color: Colors.green, width: 2, ), ), ), ), const SizedBox(height: 20), TextField( controller: myController2, decoration: InputDecoration( labelText: 'Password', focusedBorder: const OutlineInputBorder( borderSide: BorderSide( color: Colors.green, width: 2, ), ), suffixIcon: IconButton( icon: Icon( isObscureText ? Icons.visibility : Icons.visibility_off, ), onPressed: () { setState(() { isObscureText = !isObscureText; }); }, ), ), obscureText: isObscureText, ), TextButton( onPressed: () { if (myController1.text.toLowerCase() == 'hung' && myController2.text == '123') { Navigator.push( context, MaterialPageRoute( builder: (context) => const Messenger(), )); } else { showCredentials = true; setState(() {}); } }, child: const Text('Đăng nhập'), ), if (showCredentials) const Text('Sai tài khoản hoặc mật khẩu') ], ), ), ); } }