startListenUserConsent method
Future<void>
startListenUserConsent(
- ExtractStringCallback codeExtractor, {
- List<
OTPStrategy> ? strategies, - String? senderNumber,
Start listen for OTP code with User Consent API sms by default could be added another input as OTPStrategy.
Implementation
Future<void> startListenUserConsent(
ExtractStringCallback codeExtractor, {
List<OTPStrategy>? strategies,
String? senderNumber,
}) {
final smsListen = otpInteractor.startListenUserConsent(senderNumber);
final strategiesListen = strategies?.map((e) => e.listenForCode());
final list = [
if (platform.isAndroid) smsListen,
if (strategiesListen != null) ...strategiesListen,
];
return Stream.fromFutures(list).first.then(
(value) {
if (autoStop) {
stopListen();
}
text = codeExtractor(value);
},
).catchError(
// ignore: avoid_types_on_closure_parameters
(Object error) {
if (autoStop) {
stopListen();
}
if (error is PlatformException && error.code == '408') {
onTimeOutException?.call();
} else if (error is Exception) {
errorHandler?.call(error);
} else {
throw Exception('Unexpected error: $error');
}
},
);
}