genericAddContact method
Future<void>
genericAddContact({
- required BuildContext context,
- required String? value,
- required ContactInfoType type,
- required Function setOtp,
- required String flag,
- required bool primary,
Implementation
Future<void> genericAddContact({
required BuildContext context,
required String? value,
required ContactInfoType type,
required Function setOtp,
required String flag,
required bool primary,
}) async {
toggleLoadingIndicator(context: context, flag: flag);
// add primary contact info
if (primary) {
final Map<String, dynamic> result =
await sendEmailOtp(email: value, context: context);
if (result['status'] == 'error') {
Navigator.pop(context, <String, String>{
'status': 'error',
'message': sendOtpError(value),
});
return;
}
setOtp(result['otp']);
return;
}
// add secondary contact info
late Map<String, dynamic> result;
if (type == ContactInfoType.phone) {
result = await addSecondaryPhone(context: context, phoneNumber: value);
}
if (type == ContactInfoType.email) {
result = await addSecondaryEmail(context: context, email: value);
}
if (result['status'] == 'error') {
toggleLoadingIndicator(context: context, flag: flag, show: false);
Navigator.pop(context, <String, String>{
'status': 'error',
'message': addContactFeedback(value, hasError: true)
});
return;
}
toggleLoadingIndicator(context: context, flag: flag, show: false);
Navigator.pop(context,
<String, String>{'status': 'ok', 'message': addContactFeedback(value)});
}