1- import 'package:app/main/init.dart' ;
21import 'package:app/presentation/resources/locale/generated/l10n.dart' ;
32import 'package:app/presentation/resources/resources.dart' ;
43import 'package:app/presentation/ui/components/primary_button.dart' ;
@@ -17,14 +16,19 @@ class LoginForm extends StatefulWidget {
1716}
1817
1918class _LoginFormState extends State <LoginForm > {
20- AuthCubit get _authCubit => getIt ();
21-
2219 TextEditingController emailController = TextEditingController ();
2320 TextEditingController passwordController = TextEditingController ();
2421 bool agreeToTerms = false ;
2522
2623 final _formKey = GlobalKey <FormState >();
2724
25+ @override
26+ void dispose () {
27+ emailController.dispose ();
28+ passwordController.dispose ();
29+ super .dispose ();
30+ }
31+
2832 @override
2933 Widget build (BuildContext context) {
3034 return Form (
@@ -50,10 +54,6 @@ class _LoginFormState extends State<LoginForm> {
5054 keyboardType: TextInputType .emailAddress,
5155 controller: emailController,
5256 validator: (value) {
53- if (value == null || value.isEmpty) {
54- return S .of (context).errorEmailRequired;
55- }
56-
5757 if (! FormValidator .isEmail (value)) {
5858 return S .of (context).errorEmailInvalid;
5959 }
@@ -69,10 +69,6 @@ class _LoginFormState extends State<LoginForm> {
6969 obscureText: true ,
7070 controller: passwordController,
7171 validator: (value) {
72- if (value == null || value.isEmpty) {
73- return S .of (context).errorPasswordRequired;
74- }
75-
7672 if (! FormValidator .isStrongPassword (value)) {
7773 return S .of (context).errorPasswordWeak;
7874 }
@@ -135,11 +131,12 @@ class _LoginFormState extends State<LoginForm> {
135131 PrimaryButton (
136132 label: S .of (context).ctaLogin,
137133 onPressed: () {
138- if (_formKey.currentState? .validate () ?? false ) {
139- _authCubit.login (
140- email: emailController.text,
141- password: passwordController.text,
142- );
134+ if ((_formKey.currentState? .validate () ?? false ) &&
135+ agreeToTerms) {
136+ context.read <AuthCubit >().login (
137+ email: emailController.text,
138+ password: passwordController.text,
139+ );
143140 }
144141 },
145142 isEnabled: agreeToTerms,
0 commit comments