11import 'package:flutter/material.dart' ;
2- import '../../core/theme/app_colors.dart' ;
3- import '../../core/theme/auth_layout_template.dart' ;
4- import '../../core/theme/custom_text_field.dart' ;
5- import '../auth/presentation/ viewmodels/auth_viewmodels.dart' ;
2+ import '../../../../ core/theme/app_colors.dart' ;
3+ import '../../../../ core/theme/auth_layout_template.dart' ;
4+ import '../../../../ core/theme/custom_text_field.dart' ;
5+ import '../viewmodels/auth_viewmodels.dart' ;
66import 'register_view.dart' ;
7- import 'presentation/view / forgot_password_view.dart' ;
7+ import 'forgot_password_view.dart' ;
88
99class LoginView extends StatefulWidget {
1010 const LoginView ({super .key});
11-
1211 @override
1312 State <LoginView > createState () => _LoginViewState ();
1413}
@@ -20,105 +19,58 @@ class _LoginViewState extends State<LoginView> {
2019 Widget build (BuildContext context) {
2120 return AnimatedBuilder (
2221 animation: _vm,
23- builder: (context, _) =>
24- AuthLayoutTemplate (
25- title: 'Task Management' ,
26- subtitle: 'Chào mừng trở lại!' ,
27- submitText: 'Đăng nhập' ,
28- isLoading: _vm.isLoading,
29- showSocial: true ,
30- onSubmit: () async {
31- FocusScope .of (context).unfocus (); // Hide keyboard
32- final success = await _vm.login ();
33- if (! context.mounted) return ;
22+ builder: (context, _) => AuthLayoutTemplate (
23+ title: 'To-Do List' ,
24+ subtitle: 'Chào mừng trở lại!' ,
25+ submitText: 'Đăng nhập' ,
26+ isLoading: _vm.isLoading,
27+ showSocial: true ,
28+ onSubmit: () async {
29+ FocusScope .of (context).unfocus ();
30+ final errorMessage = await _vm.login ();
31+ if (! context.mounted) return ;
3432
35- if (success) {
36- ScaffoldMessenger .of (context).showSnackBar (
37- const SnackBar (
38- content: Text ('Đăng nhập thành công!' ),
39- backgroundColor: AppColors .success,
40- ),
41- );
42- // TODO: Navigator.pushReplacementNamed(context, '/home');
43- } else {
44- ScaffoldMessenger .of (context).showSnackBar (
45- const SnackBar (
46- content: Text ('Vui lòng điền đầy đủ thông tin!' ),
47- backgroundColor: AppColors .error,
48- ),
49- );
50- }
51- },
52- formContent: Column (
53- crossAxisAlignment: CrossAxisAlignment .end,
54- children: [
55- CustomTextField (
56- label: 'Email' ,
57- 58- icon: Icons .mail,
59- controller: _vm.emailCtrl,
60- ),
61- CustomTextField (
62- label: 'Mật khẩu' ,
63- hint: '••••••••' ,
64- icon: Icons .lock,
65- controller: _vm.passCtrl,
66- isPassword: true ,
67- obscureText: _vm.obscurePass,
68- onToggleVisibility: _vm.togglePass,
69- ),
70- TextButton (
71- onPressed: () =>
72- Navigator .push (
73- context,
74- MaterialPageRoute (
75- builder: (_) => const ForgotPasswordView ()),
76- ),
77- child: const Text (
78- 'Quên mật khẩu?' ,
79- style: TextStyle (
80- color: AppColors .primary,
81- fontWeight: FontWeight .bold,
82- ),
83- ),
84- ),
85- ],
33+ if (errorMessage == null ) {
34+ ScaffoldMessenger .of (context).showSnackBar (const SnackBar (content: Text ('Đăng nhập thành công!' ), backgroundColor: AppColors .success));
35+ } else {
36+ ScaffoldMessenger .of (context).showSnackBar (SnackBar (content: Text (errorMessage), backgroundColor: AppColors .error));
37+ }
38+ },
39+ formContent: Column (
40+ crossAxisAlignment: CrossAxisAlignment .end,
41+ children: [
42+ CustomTextField (label
: 'Email' , hint
: '[email protected] ' , icon
: Icons .mail, controller
: _vm.emailCtrl),
43+ CustomTextField (
44+ label: 'Mật khẩu' , hint: '••••••••' , icon: Icons .lock, controller: _vm.passCtrl,
45+ isPassword: true , obscureText: _vm.obscurePass, onToggleVisibility: _vm.togglePass,
8646 ),
87- footerContent: _buildFooter (
88- 'Chưa có tài khoản? ' , 'Đăng ký ngay' , () {
89- Navigator .push (
90- context,
91- MaterialPageRoute (builder: (_) => const RegisterView ()),
92- );
93- }),
94- ),
47+ TextButton (
48+ onPressed: () => Navigator .push (context, MaterialPageRoute (builder: (_) => const ForgotPasswordView ())),
49+ child: const Text ('Quên mật khẩu?' , style: TextStyle (color: AppColors .primary, fontWeight: FontWeight .bold)),
50+ ),
51+ ],
52+ ),
53+ footerContent: _buildFooter ('Chưa có tài khoản? ' , 'Đăng ký ngay' , () {
54+ Navigator .push (context, MaterialPageRoute (builder: (_) => const RegisterView ()));
55+ }),
56+ ),
9557 );
9658 }
9759
9860 Widget _buildFooter (String text, String action, VoidCallback onTap) {
9961 return Padding (
100- // Position this block 24dp above the bottom of the screen
10162 padding: const EdgeInsets .only (bottom: 24.0 ),
10263 child: Row (
10364 mainAxisAlignment: MainAxisAlignment .center,
10465 children: [
105- Text (text, style: const TextStyle (color: Colors .grey, fontSize: 16 )),
106-
66+ Text (text, style: const TextStyle (color: AppColors .textSecondary, fontSize: 16 )),
10767 TextButton (
10868 onPressed: onTap,
109- style: TextButton .styleFrom (
110- padding: const EdgeInsets .symmetric (horizontal: 8 , vertical: 12 ),
111- minimumSize: const Size (50 , 48 ),
112- ),
113- child: Text (
114- action,
115- style: const TextStyle (color: Color (0xFF5A8DF3 ),
116- fontWeight: FontWeight .bold,
117- fontSize: 16 ),
118- ),
69+ style: TextButton .styleFrom (minimumSize: const Size (50 , 48 )),
70+ child: Text (action, style: const TextStyle (color: AppColors .primary, fontWeight: FontWeight .bold, fontSize: 16 )),
11971 ),
12072 ],
12173 ),
12274 );
12375 }
124- }
76+ }
0 commit comments