onUpdate method

void onUpdate(
  1. BaseAsyncState<S> state
)
inherited

Called when the notifier's async state is updated.

Override this method to perform side effects or additional logic when the async state changes. This method is called after the state has been updated and listeners have been notified.

state is the new async state value after the update.

Use this method for:

  • Logging state changes
  • Triggering side effects based on async state changes
  • Updating external systems
  • Analytics tracking
  • Handling specific state transitions (loading → data, data → error, etc.)

Example:

class MyAsyncNotifier extends AsyncNotifier<String> with AsyncNotifierLifecycle<String> {
  MyAsyncNotifier() : super();

  @override
  void onUpdated(BaseAsyncState<String> state) {
    // Log state changes
    print('Async state updated: ${state.runtimeType}');

    // Handle specific state transitions
    if (state.isLoading) {
      print('Started loading data');
    } else if (state.hasError) {
      print('Error occurred: ${state.errorState?.message}');
    } else if (state.data != null) {
      print('Data loaded: ${state.data}');
    }
  }
}

Implementation

void onUpdate(BaseAsyncState<S> state) {}