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

A generic and customizable FastCalculatorBloc class for managing the business logic of a fast calculator. This class extends the BidirectionalBloc and provides methods for initializing the calculator, patching the calculator state, computing results, and handling various events.

This class requires three type parameters:

Inheritance
  • Object
  • Bloc<S>
  • BidirectionalBloc<E, S>
  • FastCalculatorBloc
Implementers

Constructors

FastCalculatorBloc({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.

Properties

addDebouncedComputeEvent FastCalculatorBlocDebounceEventCallback<E>
getter/setter pair
addDebouncedLoadMetadataEvent FastCalculatorBlocDebounceEventCallback<E>
getter/setter pair
addEvent → dynamic Function(BlocEvent)
Notifies the BloC of a new event which triggers mapEventToState. If dispose has already been called, any calls to dispatchEvent will be ignored and will not result in any state changes.
no setterinherited
analyticsEventController → BehaviorSubject<BlocAnalyticsEvent>
finalinherited
appSettingsBloc → FastAppSettingsBloc
The app settings bloc used by the calculator.
final
autoRefreshPeriod Duration
The auto-refresh period.
latefinal
blocState ↔ S
The current BloC's state.
getter/setter pairinherited
cancelableOperations List<CancelableOperation>
The list of cancelable operations.
getter/setter pairinherited
canInitialize bool
Whether the BloC can be initialized.
no setterinherited
closed bool
Whether the BloC is closed.
getter/setter pairinherited
context BuildContext?
no setter
currentMetadata Map<String, dynamic>
no setter
currentState → S
The current BloC's state.
no setterinherited
debouceComputeEvents bool
Determines if compute events should be debounced or not.
latefinal
debugLabel String?
The debug label used to identify the bloc in the logs.
latefinal
defaultCalculatorState ↔ S
The default state of the calculator.
getter/setter pair
delegate FastCalculatorBlocDelegate?
latefinal
dispatchState → dynamic Function(S)
Notifies the BloC of a new state which triggers onData.
no setterinherited
enableForceBuildEvents bool
Enable force build events, if you want to force the rendering of the bloc builder. Indicates if the event-state history should be saved.
finalinherited
errorController → PublishSubject<BlocError>
The error controller.
finalinherited
eventStateHistory Map<E, List<String>>
The history map that stores the event-state history.
finalinherited
eventStateHistorySize int
The maximum size of the history. Set it to null to disable the limit.
finalinherited
eventSubscriptions StreamSubscription<S>
The event subscriptions.
getter/setter pairinherited
externalEventController → PublishSubject<E>
The external event controller which is used to control the event stream.
finalinherited
getContext → (BuildContext? Function()?)
final
hashCode int
The hash code for this object.
no setterinherited
initialState → S?
The initial state of the BloC.
finalinherited
initialStateBuilder → BlocStateBuilder<S>?
The initial state BloC builder.
finalinherited
internalEventController → PublishSubject<BlocEvent>
The internal event controller which is used to control the event stream.
finalinherited
isAutoRefreshEnabled bool
getter/setter pair
isClosed bool
Whether the BloC is closed for dispatching more events.
no setterinherited
isInitialized bool
Whether the BloC is initializing.
getter/setter pairinherited
isInitializing bool
Whether the BloC is initializing.
getter/setter pairinherited
onAnalyticsEvents Stream<BlocAnalyticsEvent>
no setterinherited
onData Stream<S>
Called whenever the BloC's state is updated.
no setterinherited
onError Stream<BlocError>
Called whenever the BloC's state is updated.
no setterinherited
onEvent Stream<E>
Called whenever an event is added to the BloC.
no setterinherited
publishers List<PublishSubject>
The list of publishers.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateController → BehaviorSubject<S>
The state controller.
finalinherited
subxList → SubxList
finalinherited
subxMap → SubxMap
finalinherited

Methods

addComputeEvent() → void
canClose() bool
Whether the BloC can be closed. Override this method to prevent the BloC from closing.
inherited
clearCalculatorState() Future<S>
Clears the calculator state and sets it to the default state.
close() → void
Closes the BloC. This method should be called when the BloC is no longer needed.
inherited
compute() Future<R>
Performs the calculation and returns the result.
debounce(BlocDebounceCallback<BlocEvent> function, {Duration delay = const Duration(milliseconds: 300)}) → BlocDebounceCallback<BlocEvent>
Creates a debounced function that only invokes function after a delay.
inherited
debounceEvent(BlocEventCallback<E> function, {Duration delay = const Duration(milliseconds: 300)}) → BlocEventCallback<E>
Debounces an event. The function will not be invoked until delay.
inherited
exportToCsv(BuildContext context) Future<void>
Exports the calculator state to CSV. Throws an exception if the exportToCsv function is not implemented.
exportToExcel(BuildContext context) Future<void>
Export the calculator state to an Excel file. Throws an exception if the exportToExcel function is not implemented.
exportToPdf(BuildContext context) Future<void>
Exports the calculator state to PDF.
getEventForState(S state) → E?
Returns the event related to the given state.
inherited
getInitialState() → S
Tries to retreive the initial BloC's state.
inherited
handleAutoRefreshComputations(dynamic event) → void
handleComputedEvent(FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
Handles the computed event by updating the state with the computed results.
handleComputeError(dynamic error) Future<void>
Handles errors that occur during computation.
handleComputeEvent() Stream<S>
Handles the compute event by updating the state flags and performing the calculation.
handleInitEvent() Stream<S>
Handles the initialization event by initializing the calculator and emitting the new state.
handleInitializedEvent() Stream<S>
Handles the initialized event by updating the isInitialized and isInitializing flags.
handleInitializeFailedEvent(FastCalculatorBlocEventPayload<R>? payload) Stream<S>
Handles an event where the calculator fails to initialize by resetting the isInitialized and isInitializing flags and emitting a new state.
handleInternalError(dynamic error, StackTrace stackTrace) → void
Handles internal errors that occur within the bloc.
override
handleLoadMetadataEvent() Stream<S>
Handles the load metadata event by loading the calculator metadata. Emits the new state.
handlePatchMetadataEvent(FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
handlePatchValueEvent(FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
Handles the patch value event by updating a single field in the calculator state.
handleResetEvent() Stream<S>
Handles the reset event by setting the isInitialized and isInitializing flags to false.
handleSettingsChanges(FastAppSettingsBlocState state) → void
Handles settings changes.
initialize() Future<void>
Initializes the calculator by setting up required resources.
initializeCalculatorState() Future<S>
Initializes the calculator state with default values.
initializeDefaultCalculatorState() Future<S>
Initializes the default calculator state.
initState() → S
Optional callback method to initialize the BloC's state.
inherited
isCalculatorStateDirty() Future<bool>
Checks if the calculator state is dirty, i.e., different from the default state.
isCalculatorStateValid() Future<bool>
Checks if the calculator state is valid.
loadMetadata() Future<Map<String, dynamic>>
Loads the metadata of the calculator.
mapEventToState(FastCalculatorBlocEvent<FastCalculatorResults> event) Stream<S>
Maps an event to a new state and emits the state changes as a stream.
override
mergeMetadata(Map<String, dynamic> partialMetadata) Map<String, dynamic>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patchCalculatorState(String key, dynamic value) Future<S?>
Updates a single field in the calculator state.
performCancellableAsyncOperation<T>(Future<T> opreation) Future<T?>
Performs an asynchronous operation and cancels it if the BloC is closed.
inherited
processCalculatorValueChange(S? state) Stream<S>
resetBloc() → void
inherited
resetCalculatorState(String key) Future<S?>
retrieveCalculatorStateStatus() Future<(bool, bool)>
Retrieves the current status of the calculator state, including validity and dirtiness.
retrieveDefaultResult() Future<R>
Retrieves the default result.
sampleEvent(BlocEventCallback<E> function, {Duration delay = const Duration(milliseconds: 300)}) → BlocEventCallback<E>
inherited
saveCalculatorState() Future<bool>
Saves the calculator state.
setState(S nextState) → void
Set the BloC state.
inherited
shareCalculatorState(BuildContext context) Future<void>
Shares the calculator state.
shouldProcessEventInOrder() bool
Determines if events should be processed in order.
override
throttle(BlocThrottleCallback<BlocEvent> function, {Duration duration = const Duration(milliseconds: 300)}) → BlocThrottleCallback<BlocEvent>
Creates a throttled function that only invokes function at most once per every duration.
inherited
throttleEvent(BlocEventCallback<E> function, {Duration duration = const Duration(milliseconds: 300)}) → BlocEventCallback<E>
Throttles an event. The event will be ignored if it is dispatched within the specified duration. The last event will be dispatched after the duration has passed.
inherited
toString() String
A string representation of this object.
inherited
transformError(dynamic error, StackTrace stackTrace) → BlocError?
Transforms the error before it is emitted.
inherited
updateEventStateHistory(E event, S nextState) → void
Updates the event-state history. The event-state history is used to determine the event related to a given state.
inherited
willCompute() Stream<S>
The initializer to yield the current state before computation begins.

Operators

operator ==(Object other) bool
The equality operator.
inherited