init method

void init(
  1. {dynamic showLoading = true}
)

Handle a remote call and emit the appropriate state

Implementation

void init({showLoading = true}) async {
  if (showLoading) safeEmit(CleanStateLoading<T>());
  final response = await remoteCall().run();
  safeEmit(response.match(
    errorHandler,
    successHandler,
  ));

  /// complete the completer only if the loading is not shown
  /// this is to prevent the refresh indicator being shown for a split second
  /// when the data is already available
  ///
  /// we only want to show the refresh indicator only when showLoading is false
  if (!showLoading) complete();
}