FastCalculatorBloc<E extends FastCalculatorBlocEvent<FastCalculatorResults>, S extends FastCalculatorBlocState<FastCalculatorFields, FastCalculatorResults>, R extends FastCalculatorResults> constructor

FastCalculatorBloc<E extends FastCalculatorBlocEvent<FastCalculatorResults>, S extends FastCalculatorBlocState<FastCalculatorFields, FastCalculatorResults>, R extends FastCalculatorResults>({
  1. required S? initialState,
  2. Duration autoRefreshPeriod = const Duration(minutes: 1),
  3. bool enableForceBuildEvents = true,
  4. bool debouceComputeEvents = false,
  5. String? debugLabel,
  6. FastCalculatorBlocDelegate? delegate,
  7. bool? isAutoRefreshEnabled = false,
  8. BuildContext? getContext()?,
})

Constructs a new FastCalculatorBloc instance.

initialState is required and represents the initial state of the bloc. debugLabel is an optional identifier for the bloc in the logs. debouceComputeEvents determines if compute events should be debounced, and defaults to false.

Implementation

FastCalculatorBloc({
  required super.initialState,
  this.autoRefreshPeriod = const Duration(minutes: 1),
  super.enableForceBuildEvents = true,
  this.debouceComputeEvents = false,
  this.debugLabel,
  this.delegate,
  bool? isAutoRefreshEnabled = false,
  this.getContext,
}) {
  if (debouceComputeEvents) {
    debugPrint('`debouceComputeEvents` is enabled for $runtimeType');
  } else {
    debugPrint('`debouceComputeEvents` is disabled for $runtimeType');
  }

  _analyticsDebouncer = Debouncer(milliseconds: 5000); // 5 seconds

  addDebouncedComputeEvent = debounceEvent((event) {
    if (!closed) addEvent(event);
  });

  addDebouncedLoadMetadataEvent = debounceEvent((event) {
    if (!closed) addEvent(event);
  });

  subxList.add(appSettingsBloc.onData.listen(handleSettingsChanges));
  isAutoRefreshEnabled = isAutoRefreshEnabled ?? false;
}