Skip to content

Commit

Permalink
#223 mobile number length validation
Browse files Browse the repository at this point in the history
Ensure mobile number length validation accommodates both Swedish and Indian formats.
  • Loading branch information
lijogeorgep authored and georgepadayatti committed Nov 21, 2023
1 parent 2754718 commit 031bd26
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 52 deletions.
22 changes: 12 additions & 10 deletions lib/app/modules/register/controllers/register_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down Expand Up @@ -198,7 +198,10 @@ class RegisterController extends BaseController {
}

Future<void> 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);
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -427,7 +430,6 @@ class RegisterController extends BaseController {
print('dataAttributes values ${dataAttributes[0]}');
}
}

} catch (e) {
hideLoading();
GetSnackToast(message: e.toString());
Expand All @@ -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<String, dynamic> 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());
Expand Down
80 changes: 38 additions & 42 deletions lib/app/modules/register/views/register_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class RegisterView extends BaseView<RegisterController> {
}

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(
Expand Down Expand Up @@ -267,7 +271,7 @@ class RegisterView extends BaseView<RegisterController> {
},
),
TextSpan(
text: ' '+ appLocalization.registerAnd + ' ',
text: ' ' + appLocalization.registerAnd + ' ',
style: const TextStyle(
fontSize: 15,
color: Colors.black,
Expand Down Expand Up @@ -443,10 +447,8 @@ class RegisterView extends BaseView<RegisterController> {
elevation: 0,
margin: const EdgeInsets.symmetric(horizontal: 0, vertical: 16),
color: AppColors.pageBackground,

shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(cardRadius),

),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -468,43 +470,37 @@ class RegisterView extends BaseView<RegisterController> {
}

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) {
Expand Down Expand Up @@ -615,7 +611,7 @@ class RegisterView extends BaseView<RegisterController> {
),
recognizer: TapGestureRecognizer()
..onTap = () {
_registerController.onSkipTap();
_registerController.onSkipTap();
},
),
],
Expand Down

0 comments on commit 031bd26

Please sign in to comment.