execute method

  1. @protected
Future<void> execute(
  1. EitherFailureOr<T> function, {
  2. PreHandleData<T>? onDataReceived,
  3. PreHandleFailure? onFailureOccurred,
  4. bool withLoadingState = true,
  5. bool globalLoading = false,
  6. bool globalFailure = true,
})
inherited

Executes received function with additional parameters to control if loading state should be set while executing function by providing withLoadingState param.

Also if you want loading shown over all screens, it can se set via globalLoading param. To show failure over all screens instead changing the state, it can be set via globalFailure params. If your method gets called more than once in a short period, you can set withDebounce param to true to wait for debounceDuration, if debounceDuration is not provided, default will be used. To filter and control which data will update the state, onDataReceived callback can be passed. Alternatively, if callback always return false, custom data handling can be implemented. To filter and control which failure will update the state or be shown globally, onFailureOccurred callback can be passed. Similar to onDataReceived if always returned false, custom failure handling can be implemented.

Implementation

@protected
Future<void> execute(
  EitherFailureOr<DataState> function, {
  PreHandleData<DataState>? onDataReceived,
  PreHandleFailure? onFailureOccurred,
  bool withLoadingState = true,
  bool globalLoading = false,
  bool globalFailure = true,
}) async {
  _setLoading(withLoadingState, globalLoading);

  final result = await function;
  _handleResult(
    result,
    onDataReceived,
    onFailureOccurred,
    withLoadingState,
    globalLoading,
    globalFailure,
  );
}