From 1d81b36954478d19b3c72cc52aa74f551b6e305e Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Fri, 2 Aug 2024 10:47:39 +0200 Subject: [PATCH] update siugnin and register to cover validations --- .../patient_manager/lib/pages/register.dart | 52 +++++++++++-------- .../patient_manager/lib/pages/signin.dart | 48 +++++++---------- 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/Frontend/patient_manager/lib/pages/register.dart b/Frontend/patient_manager/lib/pages/register.dart index e15b826b..c1604111 100644 --- a/Frontend/patient_manager/lib/pages/register.dart +++ b/Frontend/patient_manager/lib/pages/register.dart @@ -122,7 +122,7 @@ class _RegisterState extends State { //print("Here1"); } else if (userCreated["status"] == "FIELD_ERROR") { Navigator.of(context).pop(); - passwordError(); + passwordReqError(); } else { Navigator.of(context).pop(); internetConnectionPopUp(); @@ -162,6 +162,15 @@ class _RegisterState extends State { } void passwordError() { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Password Match"); + }, + ); + } + + void passwordReqError() { showDialog( context: context, builder: (context) { @@ -181,6 +190,21 @@ class _RegisterState extends State { ); } + void validateInput() async { + if (emailController.text.isEmpty || + passwordController.text.isEmpty || + confirmPasswordController.text.isEmpty) { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Input Error"); + }, + ); + } else { + await signUserUp(); + } + } + void toggle() { setState(() { _obscureText = !_obscureText; @@ -195,16 +219,7 @@ class _RegisterState extends State { onKeyEvent: (event) async { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) { - if (emailController.text.isEmpty || passwordController.text.isEmpty) { - showDialog( - context: context, - builder: (context) { - return const MyErrorMessage(errorType: "Input Error"); - }, - ); - } else { - await signUserUp(); - } + validateInput(); } }, child: Scaffold( @@ -260,6 +275,7 @@ class _RegisterState extends State { controller: passwordController, hintText: 'Password', required: true, + signIn: false, ), ), //spacer @@ -271,6 +287,7 @@ class _RegisterState extends State { controller: confirmPasswordController, hintText: 'Confirm Password', required: true, + signIn: false, ), ), //spacer @@ -288,18 +305,7 @@ class _RegisterState extends State { .theme .primaryColor(), onTap: () async { - if (emailController.text.isEmpty || - passwordController.text.isEmpty) { - showDialog( - context: context, - builder: (context) { - return const MyErrorMessage( - errorType: "Input Error"); - }, - ); - } else { - await signUserUp(); - } + validateInput(); }, ), ), diff --git a/Frontend/patient_manager/lib/pages/signin.dart b/Frontend/patient_manager/lib/pages/signin.dart index a0536e64..734f52c9 100644 --- a/Frontend/patient_manager/lib/pages/signin.dart +++ b/Frontend/patient_manager/lib/pages/signin.dart @@ -91,6 +91,22 @@ class _SignInState extends State { ); } + void validateInput() async { + if (emailController.text.isEmpty || passwordController.text.isEmpty) { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Input Error"); + }, + ); + } else { + await signUserIn(); + if (successfulSignIn) { + Navigator.of(context).pushNamed('/home'); + } + } + } + @override Widget build(BuildContext context) { return KeyboardListener( @@ -99,19 +115,7 @@ class _SignInState extends State { onKeyEvent: (event) async { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) { - if (emailController.text.isEmpty || passwordController.text.isEmpty) { - showDialog( - context: context, - builder: (context) { - return const MyErrorMessage(errorType: "Input Error"); - }, - ); - } else { - await signUserIn(); - if (successfulSignIn) { - Navigator.of(context).pushNamed('/home'); - } - } + validateInput(); } }, child: Scaffold( @@ -167,6 +171,7 @@ class _SignInState extends State { controller: passwordController, hintText: 'Password', required: true, + signIn: true, ), ), //spacer @@ -184,22 +189,7 @@ class _SignInState extends State { .theme .primaryColor(), onTap: () async { - if (emailController.text.isEmpty || - passwordController.text.isEmpty) { - showDialog( - context: context, - builder: (context) { - return const MyErrorMessage( - errorType: "Input Error"); - }, - ); - } else { - await signUserIn(); - //print(successfulSignIn); - if (successfulSignIn) { - Navigator.of(context).pushNamed('/home'); - } - } + validateInput(); }, ), ),