-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregister_view.dart
More file actions
94 lines (90 loc) · 3.5 KB
/
register_view.dart
File metadata and controls
94 lines (90 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import 'package:flutter/material.dart';
import 'package:task_management_app/features/auth/presentation/view/login_view.dart';
import '../../../../core/theme/auth_layout_template.dart';
import '../../../../core/theme/custom_text_field.dart';
import '../viewmodels/auth_viewmodels.dart';
class RegisterView extends StatefulWidget {
const RegisterView({super.key});
@override
State<RegisterView> createState() => _RegisterViewState();
}
class _RegisterViewState extends State<RegisterView> {
final _vm = RegisterViewModel();
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _vm,
builder: (context, _) => AuthLayoutTemplate(
title: 'Tạo tài khoản mới',
subtitle: 'Bắt đầu quản lý công việc khoa học',
submitText: 'Đăng ký',
compactMode: true,
isLoading: _vm.isLoading,
showSocial: true,
onSubmit: () async {
FocusScope.of(context).unfocus();
final errorMessage = await _vm.register();
if (!context.mounted) return;
if (errorMessage == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Đăng ký thành công!'),
backgroundColor: Theme.of(context).colorScheme.tertiary,
),
);
// Return to the existing LoginView to avoid stacking duplicate login routes.
Navigator.pop(context);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(errorMessage),
backgroundColor: Theme.of(context).colorScheme.error,
),
);
}
},
formContent: Column(
children: [
CustomTextField(label: 'Họ tên', hint: 'Nhập họ và tên', icon: Icons.person, controller: _vm.usernameCtrl),
CustomTextField(label: 'Email', hint: '[email protected]', icon: Icons.mail, controller: _vm.emailCtrl),
CustomTextField(
label: 'Mật khẩu', hint: '••••••••', icon: Icons.lock, controller: _vm.passCtrl,
isPassword: true, obscureText: _vm.obscurePass, onToggleVisibility: _vm.togglePass,
),
CustomTextField(
label: 'Xác nhận mật khẩu', hint: '••••••••', icon: Icons.shield, controller: _vm.confirmPassCtrl,
isPassword: true, obscureText: _vm.obscurePass, onToggleVisibility: _vm.togglePass,
),
],
),
footerContent: Padding(
padding: const EdgeInsets.only(bottom: 14.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Đã có tài khoản? ',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 15,
),
),
TextButton(
onPressed: () => Navigator.pop(context),
style: TextButton.styleFrom(minimumSize: const Size(50, 40)),
child: Text(
'Đăng nhập',
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
),
],
),
),
),
);
}
}