useEndpointResend function
Future<void>
useEndpointResend({
- required BuildContext context,
- required dynamic appWrapperContext,
- required String phoneNumber,
- required int step,
- required Function retrySendOtpEndpoint,
- required Function toggleResend,
- required Function showErr,
- required Function resetTimer,
- required OnOTPReceivedNavigateCallback onOTPCallback,
- Client? httpClient,
useEndpointResend send a resend otp request via REST endpoint. This function should only be used in the context of SILResendPhoneCode widget. It's extracted here for testability
Implementation
Future<void> useEndpointResend(
{required BuildContext context,
required dynamic appWrapperContext,
required String phoneNumber,
required int step,
required Function retrySendOtpEndpoint,
required Function toggleResend,
required Function showErr,
required Function resetTimer,
required OnOTPReceivedNavigateCallback onOTPCallback,
Client? httpClient}) async {
final Client client = httpClient ?? Client();
toggleResend();
showErr(val: false);
try {
final Response response = await client.post(
Uri.parse(retrySendOtpEndpoint(appWrapperContext).toString()),
body: json.encode(<String, dynamic>{
'phoneNumber': phoneNumber,
'retryStep': step,
}),
headers: requestHeaders,
);
// reset the timer
resetTimer();
// return the new otp
// Navigator.pop(context, json.decode(response.body)['otp'] );
final Map<String, dynamic> body =
json.decode(response.body) as Map<String, dynamic>;
onOTPCallback(body['otp'] as String);
toggleResend();
} catch (e) {
toggleResend();
showErr(val: true);
}
}