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> ({
- required S? initialState,
- Duration autoRefreshPeriod = const Duration(minutes: 1),
- bool enableForceBuildEvents = true,
- bool debouceComputeEvents = false,
- String? debugLabel,
- FastCalculatorBlocDelegate? delegate,
- bool? isAutoRefreshEnabled = false,
- 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;
}