emitAsync method

Future<void> emitAsync(
  1. Future<CounterState> futureState
)
inherited

Emits a state from a Future.

This method waits for the futureState to complete and then emits the result. If the Future completes with an error, the error is rethrown.

Example:

Future<void> loadData() async {
  await emitAsync(fetchDataFromApi().then(
    (data) => state.copyWith(data: data, isLoading: false)
  ));
}

Implementation

Future<void> emitAsync(Future<S> futureState) async {
  try {
    final newState = await futureState;
    emit(newState);
  } catch (error) {
    // Let the concrete implementation handle errors
    rethrow;
  }
}