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