UseContext<T extends ReactterContext> class
A ReactterHook that helps to get the context of ReactterContext by T
with or without id.
final appContextHook = UseContext<AppContext>();
final appContextWithIdHook = UseContext<AppContext>('uniqueId');
The context that you need to get, to must be created by ReactterInstanceManager:
Reactter.create<AppContext>(() => AppContex());
or created by ReactterProvider
of flutter_reactter
You can get instance, using instance getter:
final appContextHook = UseContext<AppContext>();
print(appContextHook.instance);
instance returns null, when the instance is not found or it hasn't created yet.
To wait for the instance to be created, you need to use the UseEffect hook.
final appContextHook = UseContext<AppContext>(null, this);
print(appContextHook.instance); // return null
UseEffect(() {
print(appContextHook.instance); // return instance of AppContext
}, [appContextHook]);
You should call dispose when it's no longer needed.
See also:
- ReactterContext, the instance that it returns.
- ReactterInstanceManager, a instances manager.
- UseEffect, a side-effect manager.
- Inheritance
-
- Object
- ReactterHookManager
- ReactterHook
- UseContext
Constructors
- UseContext({String? id, ReactterContext? context})
Properties
- context → ReactterContext?
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String?
-
final
- instance → T?
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void -
Call when this hook is no longer needed.
override
-
listenHooks(
List< ReactterHook> hooks) → void -
Suscribes to all
hooks
given.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → void -
Forces update and notifies to listeners that it did update
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
[covariant Function? callback]) → void -
Executes
fnUpdate
, and notify the listeners about to update.inherited -
updateAsync(
[covariant Function? callback]) → Future< void> -
Executes
fnUpdate
, and notify the listeners about to update as async way.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited