InjectedAuth<T, P> class abstract

Injection of a state that can authenticate and authorize a user.

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

The approach consists of the following steps:

  • Define uer User Model. (The name is up to you).
  • You may define a class (or enum) to parametrize the query.
  • Your repository must implements IAuth<T, P> where T is the User type and P is the parameter type. with IAuth<T, P> you define sign-(in, up , out) methods.
  • Instantiate an InjectedAuth object using RM.injectAuth method.
  • Later on use InjectedAuth.auth.signUp, InjectedAuth.auth.signIn, and InjectedAuth.auth.signOut for sign up, sign in, sign out.
  • In the UI you can use OnAuthBuilder to listen the this injected state and define the appropriate view for each state.

See: InjectedAuth.auth, _AuthService.signUp, _AuthService.singIn, _AuthService.signOut, _AuthService.refreshToken,and OnAuthBuilder

Implemented types
Available extensions

Constructors

InjectedAuth()

Properties

auth → _AuthService<T, P>
Object that encapsulates the signIn, signUp, signOut methods
no setter
canRedoState → bool
Whether the state can be redone.
no setterinherited
canUndoState → bool
Whether the state can be done
no setterinherited
connectionState → ConnectionState
no setterinherited
currentWidget → Widget?

Available on Injected<List<SavedPopWidget?>>, provided by the PopWidgetsX extension

no setter
customStatus ↔ Object?
Custom status of the state. Set manually to mark the state with a particular tag to be used in your logic.
getter/setter pairinherited
error → dynamic
The error
no setterinherited
hasData → bool
The state is mutated successfully.
no setterinherited
hasError → bool
The stats has error
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
hasObservers → bool
Whether the state has listeners or not
no setterinherited
isDone → bool
The state is mutated using a stream and the stream is done.
no setterinherited
isIdle → bool
The state is initialized and never mutated.
no setterinherited
isSigned → bool
Whether the a user is signed or not
no setter
isStateInitialized → bool
no setterinherited
isWaiting → bool
The state is waiting for and asynchronous task to end.
no setterinherited
rebuild → _Rebuild<T, P>

Available on InjectedAuth<T, P>, provided by the InjectedAuthX extension

Listen to InjectedAuth
no setter
rebuild → _Rebuild<T>

Available on ReactiveModel<T>, provided by the ReactiveModeX extension

listen to the state
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
snapState → SnapState<T>
A snap representation of the state
no setterinherited
state ↔ T
The current state
getter/setter pairinherited
stateAsync ↔ Future<T>
The current Async state
getter/setter pairinherited
subscription ↔ StreamSubscription?
It is not null if the state is waiting for a Future or is subscribed to a Stream
getter/setter pairinherited

Methods

addCleaner(VoidCallback listener) → VoidCallback
Add a callback to be executed when the state is disposed of.
inherited
addObserver({required ObserveReactiveModel listener, bool shouldAutoClean = false, bool isSideEffects = true}) → VoidCallback
Add observer to this state.
inherited
builder(Widget builder(), {void initState()?, void onSetState(SnapState<T?> state)?, void onAfterBuild()?, void dispose()?, ShouldRebuild? shouldRebuild, Object? watch()?, String? debugPrintWhenRebuild, String? tag}) → Widget

Available on Injected<T?>, provided by the StateRebuilderExtension extension

Simple builder without passing state.
builderData<R>(Widget builder(R data), {Widget onWaiting()?, Widget onError(dynamic error)?, void initState()?, void onSetState(SnapState<T?> state)?, void onSetStateData(R data)?, void onAfterBuild()?, void dispose()?, bool shouldRebuild(SnapState, SnapState)?, Object? watch()?, String? debugPrintWhenRebuild, String? tag}) → Widget

Available on Injected<T?>, provided by the StateRebuilderExtension extension

Data builder handling waiting/error/data states uniformly.
builderState(Widget builder(SnapState<T?> state), {void initState()?, void onSetState(SnapState<T?> state)?, void onAfterBuild()?, void dispose()?, ShouldRebuild? shouldRebuild, Object? watch()?, String? debugPrintWhenRebuild, String? tag}) → Widget

Available on Injected<T?>, provided by the StateRebuilderExtension extension

Builder that exposes SnapState.
call(BuildContext context, {bool defaultToGlobal = false}) → Injected<T>
Obtain the Injected model from the nearest InheritedWidget inserted using inherited.
inherited
cleanState() → void
Clean the state
inherited
clearUndoStack() → void
Clear undoStack;
inherited
deletePersistState() → void
Delete the state form the persistence store
inherited
dispose() → void
Dispose the state
inherited
disposeIfNotUsed() → void
Dispose the state if it has no listener
inherited
getRepoAs<R extends IAuth<T, P>>() → R
Get the auth repository of type R
inherited({Key? key, required Widget builder(BuildContext), required FutureOr<T> stateOverride()?, bool connectWithGlobal = true, SideEffects<T>? sideEffects, String? debugPrintWhenNotifiedPreMessage, String toDebugString(T?)?}) → Widget
Provide the injected model using an InheritedWidget that wraps its state.
inherited
initializeState() → FutureOr<T?>
Initialize the state
inherited
injectAuthMock(IAuth<T, P> fakeRepository()?) → void
Inject a fake implementation of this injected model.
injectFutureMock(Future<T> fakeCreator()) → void
Inject a fake future implementation of this injected model.
inherited
injectMock(T fakeCreator()) → void
Inject a fake implementation of this injected model.
inherited
injectStreamMock(Stream<T> fakeCreator()) → void
Inject a fake stream implementation of this injected model.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify() → void
Notify observers
inherited
of(BuildContext context, {bool defaultToGlobal = false}) → 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(T data)}) → R
Listen to the injected Model and rebuild when it emits a notification.
inherited
onOrElse<R>({R onIdle()?, R onWaiting()?, R onError(dynamic error, VoidCallback refreshError)?, R onData(T data)?, required R orElse(T data)}) → R
Listen to the injected Model and rebuild when it emits a notification.
inherited
persistState() → void
Persist the state
inherited
redoState() → void
Redo to the next valid state (isWaiting and hasError are ignored)
inherited
refresh() → Future<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
safeRefresh() → void

Available on Injected, provided by the SafeRefresh extension

setState(Object? mutator(T s), {SideEffects<T>? sideEffects, StateInterceptor<T>? stateInterceptor, bool shouldOverrideDefaultSideEffects(SnapState<T> snap)?, int debounceDelay = 0, int throttleDelay = 0}) → Future<T?>
Mutate the state of the model and notify observers.
inherited
setToHasData(dynamic data) → void
Set the state to the data status
inherited
setToHasError(dynamic error, {StackTrace? stackTrace, VoidCallback? refresher}) → void
Set the state to the error status
inherited
setToIsIdle() → void
Set the state to the idle status
inherited
setToIsWaiting() → void
Set the state to the waiting status
inherited
toggle({bool shouldNotify = true, String? tag}) → void

Available on Injected<bool?>, provided by the BooleanStateRebuilderExtension extension

Toggles the boolean state, defaulting to false if null.
toggle({bool shouldNotify = true, String? tag}) → void

Available on Injected<bool>, provided by the NonNullableBooleanStateRebuilderExtension extension

toggle() → void

Available on ReactiveModel<bool>, provided by the ReactiveModelBool extension

Toggle the state and notify listeners
toString() → String
A string representation of this object.
inherited
undoState() → void
Undo to the last valid state (isWaiting and hasError are ignored)
inherited
update<R extends T>(dynamic mutator(R s), {bool shouldNotify = true, String? tag}) → void

Available on Injected<T>, provided by the NonNullableStateRebuilderExtension extension

update<R extends T?>(dynamic mutator(R s), {bool shouldNotify = true, String? tag}) → void

Available on Injected<T?>, provided by the StateRebuilderExtension extension

Safer update for nullable injected types. Always specify the generic parameter explicitly matching T?.
whenConnectionState<R>({R onIdle()?, required R onWaiting()?, required R onError(dynamic error)?, required R onData(T data)}) → R
inherited

Operators

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