InjectedCRUD<T, P> class Null safety

Injection of a state that can create, read, update and delete from a backend or database service.

This injected state abstracts the best practices of the clean architecture to come out with a simple, clean, and testable approach to manage CRUD operations.

The approach consists of the following steps:

  • Define uer Item Model. (The name is up to you).
  • You may define a class (or enum) to parametrize the query.
  • Your repository must implements ICRUD<T, P> where T is the Item type and P is the parameter type. with ICRUD<T, P> you define CRUD methods.
  • Instantiate an InjectedCRUD object using RM.injectCRUD method.
  • Later on use InjectedCRUD.crud.create, InjectedCRUD.auth.read, InjectedCRUD.auth.update, and InjectedCRUD.auth.delete item.
  • In the UI you can use ReactiveStatelessWidget, OnReactive, or ObBuilder to listen the this injected state and define the appropriate view for each state.
  • You may use InjectedCRUD.item.inherited for performant list of item rendering.

See: InjectedCRUD.crud, _CRUDService.read, _CRUDService.create, _CRUDService.update, _CRUDService.delete,InjectedCRUD.item, _Item.inherited and OnCRUDBuilder

Implemented types
Available Extensions

Constructors

InjectedCRUD()

Properties

autoDisposeWhenNotUsed bool
read-only, inherited
canRedoState bool
Whether the state can be redone.
read-only, inherited
canUndoState bool
Whether the state can be done
read-only, inherited
connectionState ConnectionState
read-only, inherited
crud → _CRUDService<T, P>
To create Read Update and Delete
read-only
customStatus Object?
Custom status of the state. Set manually to mark the state with a particular tag to be used in your logic.
read / write, inherited
debugMessage String?
read / write, inherited
error → dynamic
The error
read-only, inherited
hasData bool
The state is mutated successfully.
read-only, inherited
hasError bool
The stats has error
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
hasObservers bool
Whether the state has observers
read-only, inherited
isActive bool
Whether the state is active or not. [...]
read-only, inherited
isDone bool
The state is mutated using a stream and the stream is done.
read-only, inherited
isIdle bool
The state is initialized and never mutated.
read-only, inherited
isOnCRUD bool
Whether the state is waiting for a CRUD operation to finish
read-only
isWaiting bool
The state is waiting for and asynchronous task to end.
read-only, inherited
item → _Item<T, P>
Optimized for item displaying. Used with [...]
read-only
observerLength int
read-only, inherited
oldSnapState SnapState<List<T>>
read-only, inherited
rebuild → _Rebuild<List<T>>
Callable class used to listen to a reactive (injected) model and rebuild widget [...]
late, final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
snapState SnapState<List<T>>
A snap representation of the state
read / write, inherited
state List<T>
read / write, inherited
stateAsync Future<List<T>>
It is a future of the state. The future is active if the state is on the isWaiting status.
read-only, inherited
subscription StreamSubscription?
It is not null if the state is waiting for a Future or is subscribed to a Stream
read-only, inherited

Methods

call(BuildContext context, {bool defaultToGlobal = false}) Injected<List<T>>
Obtain the Injected model from the nearest InheritedWidget inserted using inherited. [...]
inherited
catchError(void onError(dynamic error, StackTrace s)) Future<InjectedBase<List<T>>>
inherited
clearUndoStack() → void
Clear undoStack;
inherited
deletePersistState() → void
Delete the state form the persistence store
inherited
dispose() → void
Dispose the state.
inherited
future<F>(Future<F> future(List<T> s)) Future<F> Function()
inherited
getRepoAs<R extends ICRUD<T, P>>() → R
Get the repository implementation
inherited({required Widget builder(BuildContext), Key? key, FutureOr<List<T>> stateOverride()?, bool connectWithGlobal = true, String? debugPrintWhenNotifiedPreMessage, String toDebugString(List<T>?)?}) Widget
Provide the injected model using an InheritedWidget that wraps its state. [...]
inherited
initializeState() FutureOr<List<T>>
Initialize the state
inherited
injectCRUDMock(ICRUD<T, P> fakeRepository()) → void
Inject a fake implementation of this injected model. [...]
injectFutureMock(Future<List<T>> fakeCreator()) → void
Inject a fake future implementation of this injected model. [...]
inherited
injectMock(List<T> fakeCreator()) → void
Inject a fake implementation of this injected model. [...]
inherited
injectStreamMock(Stream<List<T>> fakeCreator()) → void
Inject a fake stream implementation of this injected model. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notify() → void
Notify observers
inherited
of(BuildContext context, {bool defaultToGlobal = false}) List<T>
Obtain the state from the nearest InheritedWidget inserted using inherited. [...]
inherited
onAll<R>({R onIdle()?, required R onWaiting()?, required R onError(dynamic error, VoidCallback refreshError)?, required R onData(List<T> data)}) → R
inherited
onErrorRefresher() → void
IF the state is in the hasError status, The last callback that causes the error can be reinvoked.
inherited
onOrElse<R>({R onIdle()?, R onWaiting()?, R onError(dynamic error, VoidCallback refreshError)?, R onData(List<T> data)?, required R orElse(List<T> data)}) → R
inherited
persistState() → void
Persist the state
inherited
redoState() → void
Redo to the next valid state (isWaiting and hasError are ignored)
inherited
refresh() Future<List<T>?>
Refresh the Injected state. Refreshing the state means reinitialize it and reinvoke its creation function and notify its listeners. [...]
inherited
reInherited({Key? key, required BuildContext context, required Widget builder(BuildContext)}) Widget
Provide the Injected model to another widget tree branch.
inherited
setState<R>(FutureOr<R> fn(List<T> s), {void onData(List<T> data)?, void onError(dynamic error)?, On<void>? onSetState, void onRebuildState()?, SideEffects<List<T>>? sideEffects, int debounceDelay = 0, int throttleDelay = 0, bool shouldAwait = false, bool skipWaiting = false, BuildContext? context, bool shouldOverrideDefaultSideEffects(SnapState<List<T>> snap)?}) Future<List<T>>
Mutate the state of the model and notify observers. [...]
inherited
subscribeToRM(void fn(SnapState<List<T>>? snap)) VoidCallback
Subscribe to the state
inherited
toggle() → void
If the state is bool, toggle it and notify listeners [...]
inherited
toString() String
A string representation of this object. [...]
inherited
undoState() → void
Undo to the last valid state (isWaiting and hasError are ignored)
inherited
whenConnectionState<R>({required R onIdle(), required R onWaiting(), required R onData(List<T> snapState), required R onError(dynamic error), bool catchError = true}) → R
Exhaustively switch over all the possible statuses of connectionState. Used mostly to return Widgets.
inherited

Operators

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