genericAddContact method

Future<void> genericAddContact({
  1. required BuildContext context,
  2. required String? value,
  3. required ContactInfoType type,
  4. required Function setOtp,
  5. required String flag,
  6. 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)});
}