Facebook
From hung, 2 Months ago, written in Dart.
Embed
Download Paste or View Raw
Hits: 170
  1. import 'package:flutter/material.dart';
  2. import 'messenger.dart';
  3.  
  4. void main() {
  5.   runApp(const MaterialApp(
  6.       debugShowCheckedModeBanner: false, home: LoginScreen()));
  7. }
  8.  
  9. class LoginScreen extends StatefulWidget {
  10.   const LoginScreen({Key? key}) : super(key: key);
  11.  
  12.   @override
  13.   State<LoginScreen> createState() => _LoginScreenState();
  14. }
  15.  
  16. class _LoginScreenState extends State<LoginScreen> {
  17.   final myController1 = TextEditingController();
  18.   final myController2 = TextEditingController();
  19.   bool isObscureText = true;
  20.   bool showCredentials = false;
  21.  
  22.   @override
  23.   void dispose() {
  24.     myController1.dispose();
  25.     myController2.dispose();
  26.     super.dispose();
  27.   }
  28.  
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     final height = MediaQuery.of(context).size.height;
  32.  
  33.     return MaterialApp(
  34.       debugShowCheckedModeBanner: false,
  35.       home: Scaffold(
  36.         body: Column(
  37.           children: [
  38.             SizedBox(height: height * 1 / 5),
  39.             TextField(
  40.               controller: myController1,
  41.               decoration: const InputDecoration(
  42.                 labelText: 'Username',
  43.                 focusedBorder: OutlineInputBorder(
  44.                   borderSide: BorderSide(
  45.                     color: Colors.green,
  46.                     width: 2,
  47.                   ),
  48.                 ),
  49.               ),
  50.             ),
  51.             const SizedBox(height: 20),
  52.             TextField(
  53.               controller: myController2,
  54.               decoration: InputDecoration(
  55.                 labelText: 'Password',
  56.                 focusedBorder: const OutlineInputBorder(
  57.                   borderSide: BorderSide(
  58.                     color: Colors.green,
  59.                     width: 2,
  60.                   ),
  61.                 ),
  62.                 suffixIcon: IconButton(
  63.                   icon: Icon(
  64.                     isObscureText ? Icons.visibility : Icons.visibility_off,
  65.                   ),
  66.                   onPressed: () {
  67.                     setState(() {
  68.                       isObscureText = !isObscureText;
  69.                     });
  70.                   },
  71.                 ),
  72.               ),
  73.               obscureText: isObscureText,
  74.             ),
  75.             TextButton(
  76.               onPressed: () {
  77.                 if (myController1.text.toLowerCase() == 'hung' &&
  78.                     myController2.text == '123') {
  79.                   Navigator.push(
  80.                       context,
  81.                       MaterialPageRoute(
  82.                         builder: (context) => const Messenger(),
  83.                       ));
  84.                 } else {
  85.                   showCredentials = true;
  86.                   setState(() {});
  87.                 }
  88.               },
  89.               child: const Text('Đăng nhập'),
  90.             ),
  91.             if (showCredentials) const Text('Sai tài khoản hoặc mật khẩu')
  92.           ],
  93.         ),
  94.       ),
  95.     );
  96.   }
  97. }
  98.