startOperation method

Future<void> startOperation()

Implementation

Future<void> startOperation() async {
  _isLoading = true;
  _errorMessage = null;
  _isSuccess = false;
  _isCanceled = false;
  _hasStarted = true;
  _elapsed = Duration.zero;
  _updateState();
  _startTimer();

  _cancelableOperation = CancelableOperation.fromFuture(
    onPressed().timeout(const Duration(minutes: 5)),
    onCancel: () {
      _isLoading = false;
      _isCanceled = true;
      _stopTimer();
      _updateState();
    },
  );

  try {
    final result = await _cancelableOperation!.value;
    if (!_isCanceled) {
      _text = result ?? initialText;
      _isSuccess = true;
    }
  } catch (error, stackTrace) {
    if (!_isCanceled) {
      _errorMessage = error.toString() + "\n" + "\n" + stackTrace.toString();
    }
  } finally {
    _isLoading = false;
    _stopTimer();
    _updateState();
  }
}