InjectedTheme<KEY> class
abstract
Injection of a state that handle app theme switching.
This injected state abstracts the best practices of the clean architecture to come out with a simple, clean, and testable approach to manage app theming.
The approach consists of the following steps:
- Instantiate an InjectedTheme object using RM.injectTheme method.
- we use the TopAppWidget that must be on top of the MaterialApp widget.
void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return TopAppWidget(//Use TopAppWidget injectedTheme: themeRM, //Set te injectedTheme builder: (context) { return MaterialApp( theme: themeRM.lightTheme, //light theme darkTheme: themeRM.darkTheme, //dark theme themeMode: themeRM.themeMode, //theme mode home: HomePage(), ); }, ); } }
Constructors
Properties
- activeTheme → ThemeData
-
no setter
- autoDisposeWhenNotUsed → bool
-
no setterinherited
- canRedoState → bool
-
Whether the state can be redone.
no setterinherited
- canUndoState → bool
-
Whether the state can be done
no setterinherited
- connectionState → ConnectionState
-
no setterinherited
- 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
- darkTheme → ThemeData?
-
Get the current dark theme.
no setter
- debugMessage ↔ String?
-
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 observers
no setterinherited
- isActive → bool
-
Whether the state is active or not.
no setterinherited
- isDarkTheme → bool
-
Wether the current mode is dark.
no setter
- 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
- isWaiting → bool
-
The state is waiting for and asynchronous task to end.
no setterinherited
- lightTheme → ThemeData
-
Get the current light theme.
no setter
- observerLength → int
-
no setterinherited
-
oldSnapState
→ SnapState<
KEY> -
no setterinherited
- rebuild → _Rebuild
-
Callable class used to listen to a reactive (injected) model and rebuild widget
latefinalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
snapState
↔ SnapState<
KEY> -
A snap representation of the state
getter/setter pairinherited
- state ↔ KEY
-
Sync state mutation.
getter/setter pairinherited-setter
-
stateAsync
↔ Future<
KEY> -
It is a future of the state. The future is active if the state is on the
isWaiting status.
getter/setter pairinherited
- subscription → StreamSubscription?
-
It is not null if the state is waiting for a Future or is subscribed to a
Stream
no setterinherited
-
supportedDarkThemes
→ Map<
KEY, ThemeData> -
Get supported dark themes
no setter
-
supportedLightThemes
→ Map<
KEY, ThemeData> -
Get supported light themes
no setter
- themeMode ↔ ThemeMode
-
The current ThemeMode
getter/setter pair
Methods
-
call(
BuildContext context, {bool defaultToGlobal = false}) → Injected< KEY> -
Obtain the Injected model from the nearest InheritedWidget inserted using inherited.
inherited
-
catchError(
void onError(dynamic error, StackTrace s)) → Future< InjectedBase< KEY> > -
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(KEY s)) → Future<F> Function() -
inherited
-
inherited(
{Key? key, required Widget builder(BuildContext), required FutureOr< KEY> stateOverride()?, bool connectWithGlobal = true, SideEffects? sideEffects, String? debugPrintWhenNotifiedPreMessage, String toDebugString(KEY?)?}) → Widget -
Provide the injected model using an InheritedWidget that wraps its state.
inherited
-
initializeState(
) → FutureOr< KEY?> -
Initialize the state
inherited
-
injectFutureMock(
Future< KEY> fakeCreator()) → void -
Inject a fake future implementation of this injected model.
inherited
-
injectMock(
KEY fakeCreator()) → void -
Inject a fake implementation of this injected model.
inherited
-
injectStreamMock(
Stream< KEY> 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}) → KEY -
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(KEY 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(KEY data)?, required R orElse(KEY 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< KEY?> -
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(KEY s), {void onData(KEY data)?, void onError(dynamic error)?, On<void> ? onSetState, void onRebuildState()?, SideEffects<KEY> ? sideEffects, SnapState<KEY> ? stateInterceptor(SnapState<KEY> currentSnap, SnapState<KEY> nextSnap)?, int debounceDelay = 0, int throttleDelay = 0, bool shouldAwait = false, bool skipWaiting = false, BuildContext? context, bool shouldOverrideDefaultSideEffects(SnapState<KEY> snap)?}) → Future<KEY> -
Mutate the state of the model and notify observers.
inherited
-
setToHasData(
KEY data) → void -
inherited
-
setToHasError(
dynamic error, {StackTrace? stackTrace, VoidCallback? refresher}) → void -
inherited
-
setToIsIdle(
) → void -
inherited
-
setToIsWaiting(
) → void -
inherited
-
subscribeToRM(
void fn(SnapState< KEY> ? 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(KEY 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