initIsolate method

Future<SendPort> initIsolate()

Implementation

Future<SendPort> initIsolate() async {
  completer = Completer<SendPort>();
  isolateToMainStream = ReceivePort();

  isolateToMainStream.listen((data) async {
    if (data is SendPort) {
      SendPort mainToIsolateStream = data;
      completer.complete(mainToIsolateStream);
    } else {
      if (data is TimerStatus) {
        if (data == TimerStatus.captchaTimer) {
          checkCaptcha();
        } else if (data == TimerStatus.mainErrorTimer) {
          checkMainError();
          checkToastifyError();
        } else if (data == TimerStatus.captchaErrorTimer) {
          checkCaptchaError();
        } else if (data == TimerStatus.otpTimer) {
          checkOtpMessage();
        }
      } else if (data is String) {
        captchaController.text = "";
        captchaImage.value = data;
      }
    }
  });
  timerIsolate = await Isolate.spawn(timer, isolateToMainStream.sendPort);
  return completer.future;
}