observer method

  1. @override
Disposer observer({
  1. void onState(
    1. S state
    )?,
  2. void onLoading(
    1. bool isLoading
    )?,
  3. void onError(
    1. dynamic error
    )?,
})

Observer the Segmented State.

EXAMPLE:

Disposer disposer = counter.observer(
  onState: (state) => print(state),
  onLoading: (loading) => print(loading),
  onError: (error) => print(error),
);

dispose();

Implementation

@override
Disposer observer({
  void Function(S state)? onState,
  void Function(bool isLoading)? onLoading,
  void Function(dynamic error)? onError,
}) {
  final call = InvocationPropagation<S>();
  call.onState = onState;
  call.onLoading = onLoading;
  call.onError = onError;
  _callList.add(call);
  return () async {
    call.onState = null;
    call.onLoading = null;
    call.onError = null;
    _callList.remove(call);
  };
}