From 634554b08d18dc342b232ac73383f2940bacc480 Mon Sep 17 00:00:00 2001 From: Fatimah Alshammari Date: Wed, 2 Mar 2022 09:57:57 +0300 Subject: [PATCH] added validation --- lib/pages/user/confirm_new_password.dart | 94 ++++++++++++++++-------- lib/pages/user/forget_password_page.dart | 13 ---- 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/lib/pages/user/confirm_new_password.dart b/lib/pages/user/confirm_new_password.dart index 851fa46..2c01938 100644 --- a/lib/pages/user/confirm_new_password.dart +++ b/lib/pages/user/confirm_new_password.dart @@ -1,5 +1,3 @@ - - import 'package:car_customer_app/api/user_api_client.dart'; import 'package:car_customer_app/classes/utils.dart'; import 'package:car_customer_app/config/routes.dart'; @@ -15,43 +13,69 @@ import 'package:flutter/material.dart'; import 'dart:convert'; import 'package:http/http.dart'; -class ConfirmNewPasswordPage extends StatelessWidget { +class ConfirmNewPasswordPage extends StatefulWidget { String userToken; ConfirmNewPasswordPage(this.userToken, {Key? key}) : super(key: key); - String newPassword = ""; + @override + State createState() => _ConfirmNewPasswordPageState(); +} - // String userToken = ""; +class _ConfirmNewPasswordPageState extends State { + String newPassword = ""; + String confirmPassword = ''; @override Widget build(BuildContext context) { return Scaffold( appBar: appBar(title: "Forget Password"), - body: Container( - width: double.infinity, - height: double.infinity, - padding: EdgeInsets.all(40), - child: Column( - children: [ - "New Password".toText24(), - 12.height, - TxtField( - hint: "Inter New Password", - value: newPassword, - onChanged: (v) { - newPassword = v; - }, - ), - 40.height, - ShowFillButton( - title: "Confirm", - width: double.infinity, - onPressed: () { - confirmPasswordOTP(context); - }, - ), - ], + body: SingleChildScrollView( + child: Container( + // width: double.infinity, + // height: double.infinity, + padding: EdgeInsets.all(40), + child: Column( + children: [ + "New Password".toText24(), + 12.height, + TextFormField( + decoration: InputDecoration( + hintText: "Enter New Password", + hintStyle: TextStyle(color: Colors.grey), + border: OutlineInputBorder( + borderRadius: const BorderRadius.all( + const Radius.circular(5.0), + ), + ), + ), + obscureText: true, + onChanged: (v) => newPassword = v, + ), + 12.height, + TextFormField( + decoration: InputDecoration( + hintText: "Confirm Password", + hintStyle: TextStyle(color: Colors.grey), + border: OutlineInputBorder( + borderRadius: const BorderRadius.all( + const Radius.circular(5.0), + ), + ), + ), + obscureText: true, + onChanged: (v) => confirmPassword = v, + ), + 40.height, + ShowFillButton( + title: "Confirm", + width: double.infinity, + onPressed: () { + if (validation()) confirmPasswordOTP(context); + }, + ), + ], + ), ), ), ); @@ -59,13 +83,23 @@ class ConfirmNewPasswordPage extends StatelessWidget { Future confirmPasswordOTP(BuildContext context) async { Utils.showLoading(context); - Response res = await UserApiClent().ForgetPassword(userToken, newPassword); + Response res = await UserApiClent().ForgetPassword(widget.userToken, newPassword); Utils.hideLoading(context); ConfirmPassword data = ConfirmPassword.fromJson(jsonDecode(res.body)); if (data.messageStatus == 1) { + Utils.showToast("Password is Updated"); navigateWithName(context, AppRoutes.loginWithPassword); } else { Utils.showToast(data.message ?? ""); } } + + bool validation() { + bool isValid = true; + if (newPassword != confirmPassword) { + Utils.showToast("Confirmation password does not match the entered password"); + isValid = false; + } + return isValid; + } } diff --git a/lib/pages/user/forget_password_page.dart b/lib/pages/user/forget_password_page.dart index 5469b91..07f9f55 100644 --- a/lib/pages/user/forget_password_page.dart +++ b/lib/pages/user/forget_password_page.dart @@ -72,19 +72,6 @@ class ForgetPasswordPage extends StatelessWidget { ], ), mFlex(10), - // 40.height, - // ShowFillButton( - // title: "Continue", - // width: double.infinity, - // onPressed: () { - // showMDialog( - // context, - // child: MessageDialog( - // title: "New Password sent used", - // ), - // ); - // }, - // ), ], ), ),