HydratedFastCalculatorBloc<E extends FastCalculatorBlocEvent<FastCalculatorResults>, S extends FastCalculatorBlocState<FastCalculatorFields, FastCalculatorResults>, D extends FastCalculatorDocument, R extends FastCalculatorResults> class abstract

An abstract class that extends FastCalculatorBloc to create a hydrated calculator bloc.

This hydrated calculator bloc can persist its state and recover from it when needed.

The class requires the following generic types: E: The type of events that the bloc responds to (must extend FastCalculatorBlocEvent).

S: The type of state that the bloc manages (must extend FastCalculatorBlocState).

D: The type of calculator document used to persist the state (must extend FastCalculatorDocument).

R: The type of calculator results managed by the bloc (must extend FastCalculatorResults).

Inheritance

Constructors

HydratedFastCalculatorBloc({required S? initialState, required FastCalculatorDataProvider<D> dataProvider, Duration autoRefreshPeriod = const Duration(minutes: 1), bool? isAutoRefreshEnabled = false, bool debouceComputeEvents = false, String? debugLabel, FastCalculatorBlocDelegate? delegate, BuildContext? getContext()?})

Properties

addDebouncedComputeEvent FastCalculatorBlocDebounceEventCallback<E>
getter/setter pairinherited
addDebouncedLoadMetadataEvent FastCalculatorBlocDebounceEventCallback<E>
getter/setter pairinherited
addDebouncedSaveEntryEvent 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.
finalinherited
autoRefreshPeriod Duration
The auto-refresh period.
latefinalinherited
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 setterinherited
currentMetadata Map<String, dynamic>
no setterinherited
currentState → S
The current BloC's state.
no setterinherited
dataProvider FastCalculatorDataProvider<D>
The dataProvider is used to persist the calculator document.
final
debouceComputeEvents bool
Determines if compute events should be debounced or not.
latefinalinherited
debugLabel String?
The debug label used to identify the bloc in the logs.
latefinalinherited
defaultCalculatorState ↔ S
The default state of the calculator.
getter/setter pairinherited
defaultDocument ↔ D
The defaultDocument is used to hydrate the bloc calculator state.
getter/setter pair
delegate FastCalculatorBlocDelegate?
latefinalinherited
dispatchState → dynamic Function(S)
Notifies the BloC of a new state which triggers onData.
no setterinherited
document ↔ D
The document is used to hydrate the bloc calculator state.
getter/setter pair
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()?)
finalinherited
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 pairinherited
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
inherited
canClose() bool
Whether the BloC can be closed. Override this method to prevent the BloC from closing.
inherited
canSaveUserEntry() Future<bool>
Determines if the user entry can be saved.
clearCalculatorDocument({bool force = false}) Future<void>
Clears the calculator document.
clearCalculatorState() Future<S>
Clears the calculator state by clearing the calculator document.
override
close() → void
Closes the bloc by disconnecting from the data provider.
override
compute() Future<R>
Performs the calculation and returns the result.
inherited
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.
inherited
exportToExcel(BuildContext context) Future<void>
Export the calculator state to an Excel file. Throws an exception if the exportToExcel function is not implemented.
inherited
exportToPdf(BuildContext context) Future<void>
Exports the calculator state to PDF.
inherited
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
inherited
handleComputedEvent(FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
Handles the computed event by updating the state with the computed results.
inherited
handleComputeError(dynamic error) Future<void>
Handles errors that occur during computation.
inherited
handleComputeEvent() Stream<S>
Handles the compute event by updating the state flags and performing the calculation.
inherited
handleInitEvent() Stream<S>
Handles the initialization event by initializing the calculator and emitting the new state.
inherited
handleInitializedEvent() Stream<S>
Handles the initialized event by updating the isInitialized and isInitializing flags.
inherited
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.
inherited
handleInternalError(dynamic error, StackTrace stackTrace) → void
Handles internal errors that occur within the bloc.
inherited
handleLoadMetadataEvent() Stream<S>
Handles the load metadata event by loading the calculator metadata. Emits the new state.
inherited
handlePatchMetadataEvent(FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
inherited
handlePatchValueEvent(covariant FastCalculatorBlocEventPayload<FastCalculatorResults>? payload) Stream<S>
Handles the patch value event by updating the calculator state and document with the given payload.
override
handleResetEvent() Stream<S>
Handles the reset event by setting the isInitialized and isInitializing flags to false.
inherited
handleSettingsChanges(FastAppSettingsBlocState state) → void
Handles settings changes.
override
initialize() Future<void>
Initializes the bloc by connecting to the data provider and retrieving the default and saved calculator documents.
override
initializeCalculatorState() Future<S>
Initializes the calculator state with the calculator document.
override
initializeDefaultCalculatorState() Future<S>
Initializes the default calculator state.
inherited
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.
inherited
isCalculatorStateValid() Future<bool>
Checks if the calculator state is valid.
inherited
loadMetadata() Future<Map<String, dynamic>>
Loads the metadata of the calculator.
inherited
mapEventToState(FastCalculatorBlocEvent<FastCalculatorResults> event) Stream<S>
Maps the events to the corresponding state changes in the bloc.
override
mergeMetadata(Map<String, dynamic> partialMetadata) Map<String, dynamic>
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patchCalculatorDocument(String key, dynamic value) Future<D?>
Patches the calculator document with the given key and value.
patchCalculatorState(String key, dynamic value) Future<S?>
Updates a single field in the calculator state.
inherited
performCancellableAsyncOperation<T>(Future<T> opreation) Future<T?>
Performs an asynchronous operation and cancels it if the BloC is closed.
inherited
persistCalculatorDocument({bool force = false}) Future<void>
Persists the calculator document.
processCalculatorValueChange(S? state) Stream<S>
inherited
resetBloc() → void
inherited
resetCalculatorDocument(String key) Future<D?>
Resets the calculator document with the given key.
resetCalculatorState(String key) Future<S?>
inherited
retrieveCalculatorDocument() Future<D>
Retrieves the calculator document by merging the saved document with the default calculator document.
retrieveCalculatorStateStatus() Future<(bool, bool)>
Retrieves the current status of the calculator state, including validity and dirtiness.
inherited
retrieveDefaultCalculatorDocument() Future<D>
Retrieves the default calculator document.
retrieveDefaultResult() Future<R>
Retrieves the default result.
inherited
sampleEvent(BlocEventCallback<E> function, {Duration delay = const Duration(milliseconds: 300)}) → BlocEventCallback<E>
inherited
saveCalculatorState() Future<bool>
Saves the calculator state by persisting the calculator document.
override
setState(S nextState) → void
Set the BloC state.
inherited
shareCalculatorState(BuildContext context) Future<void>
Shares the calculator state.
inherited
shouldProcessEventInOrder() bool
Determines if events should be processed in order.
inherited
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.
inherited

Operators

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