From 031bd265aeda1bbaa40028f927534e15a1ba9b3b Mon Sep 17 00:00:00 2001 From: Lijo George Date: Mon, 20 Nov 2023 21:30:40 +0530 Subject: [PATCH] #223 mobile number length validation Ensure mobile number length validation accommodates both Swedish and Indian formats. --- .../controllers/register_controller.dart | 22 ++--- .../modules/register/views/register_view.dart | 80 +++++++++---------- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index b230c42..57964c7 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -58,14 +58,14 @@ class RegisterController extends BaseController { pageController = PageController(initialPage: selectedPage.value); super.onInit(); } - + void registerUser() async { try { SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId??PrivacyDashboard().userId, + "userId": userId ?? PrivacyDashboard().userId, "dataAgreementID": PrivacyDashboard().backupAndRestoreDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -198,7 +198,10 @@ class RegisterController extends BaseController { } Future onNextButtonTap() async { - String pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)'; + String pattern = ""; + isdCode == "+91" + ? pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)' + : pattern = r'(^(?:[+0]9)?[0-9]{9,11}$)'; RegExp regExp = RegExp(pattern); if (firstNameController.text == "") { GetSnackToast(message: appLocalization.registerFirstNameValidationText); @@ -356,7 +359,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('DataSharing', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId??PrivacyDashboard().userId, + "userId": userId ?? PrivacyDashboard().userId, "dataAgreementID": PrivacyDashboard().donateYourDataDataAgreementId, "baseUrl": PrivacyDashboard().baseUrl }); @@ -394,7 +397,7 @@ class RegisterController extends BaseController { var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreement', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId??PrivacyDashboard().userId, + "userId": userId ?? PrivacyDashboard().userId, "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl }); @@ -427,7 +430,6 @@ class RegisterController extends BaseController { print('dataAttributes values ${dataAttributes[0]}'); } } - } catch (e) { hideLoading(); GetSnackToast(message: e.toString()); @@ -436,25 +438,25 @@ class RegisterController extends BaseController { getDataAgreementWithApiKey({required String? sharingDataAgreementID}) async { try { - showLoading(); + showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); var response = await platform.invokeMethod('GetDataAgreementWithApiKey', { "apiKey": PrivacyDashboard().apiKey, - "userId": userId??PrivacyDashboard().userId, + "userId": userId ?? PrivacyDashboard().userId, "dataAgreementID": sharingDataAgreementID, "baseUrl": PrivacyDashboard().baseUrl }); Map responseMap = json.decode(response); print('response map: $responseMap'); - hideLoading(); + hideLoading(); // call ShowDataAgreementPolicy await platform.invokeMethod('ShowDataAgreementPolicy', { "dataAgreementResponse": response, }); - // hideLoading(); + // hideLoading(); } catch (e) { hideLoading(); GetSnackToast(message: e.toString()); diff --git a/lib/app/modules/register/views/register_view.dart b/lib/app/modules/register/views/register_view.dart index e7860c9..2a4d0dc 100644 --- a/lib/app/modules/register/views/register_view.dart +++ b/lib/app/modules/register/views/register_view.dart @@ -129,7 +129,11 @@ class RegisterView extends BaseView { } Widget _internationalPhoneNumberInputWidget() { - String pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)'; + String pattern = ""; + _registerController.isdCode == "+91" + ? pattern = r'(^(?:[+0]9)?[0-9]{10,12}$)' + : pattern = r'(^(?:[+0]9)?[0-9]{9,11}$)'; + RegExp regExp = RegExp(pattern); return Padding( @@ -267,7 +271,7 @@ class RegisterView extends BaseView { }, ), TextSpan( - text: ' '+ appLocalization.registerAnd + ' ', + text: ' ' + appLocalization.registerAnd + ' ', style: const TextStyle( fontSize: 15, color: Colors.black, @@ -443,10 +447,8 @@ class RegisterView extends BaseView { elevation: 0, margin: const EdgeInsets.symmetric(horizontal: 0, vertical: 16), color: AppColors.pageBackground, - shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(cardRadius), - ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -468,43 +470,37 @@ class RegisterView extends BaseView { } Widget getDataAgreement(BuildContext context) { - return Obx( - () { - if(_registerController.dataAttributes.isNotEmpty){ - return ListView.builder( - shrinkWrap: true, - itemCount: _registerController.dataAttributes.length, - itemBuilder: (BuildContext context, index) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical:12.0), - child: Text( - _registerController.dataAttributes[index], - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Colors.black, - ), - ), - ), - if (index < _registerController.dataAttributes.length - 1) const Divider(), - ], - ); - }, - ); - } - else{ - return const SizedBox(); - } - - } - ); - - - + return Obx(() { + if (_registerController.dataAttributes.isNotEmpty) { + return ListView.builder( + shrinkWrap: true, + itemCount: _registerController.dataAttributes.length, + itemBuilder: (BuildContext context, index) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 12.0, vertical: 12.0), + child: Text( + _registerController.dataAttributes[index], + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Colors.black, + ), + ), + ), + if (index < _registerController.dataAttributes.length - 1) + const Divider(), + ], + ); + }, + ); + } else { + return const SizedBox(); + } + }); } Widget _ageWidget(BuildContext context) { @@ -615,7 +611,7 @@ class RegisterView extends BaseView { ), recognizer: TapGestureRecognizer() ..onTap = () { - _registerController.onSkipTap(); + _registerController.onSkipTap(); }, ), ],