GetItStateMixin<TState extends GetItStatefulWidgetMixin> mixin
Properties
-
context
→ BuildContext
-
The location in the tree where this widget builds.
no setterinherited
-
hashCode
→ int
-
The hash code for this object.
no setterinherited
-
mounted
→ bool
-
Whether this State object is currently in a tree.
no setterinherited
-
runtimeType
→ Type
-
A representation of the runtime type of the object.
no setterinherited
-
widget
→ TState
-
The current configuration.
no setterinherited
Methods
-
activate()
→ void
-
Called when this object is reinserted into the tree after having been
removed via deactivate.
inherited
-
allReady({void onReady(BuildContext context)?, void onError(BuildContext context, Object? error)?, Duration? timeout})
→ bool
-
returns
true
if all registered async or dependent objects are ready
and call onReady
onError
handlers when the all-ready state is reached
you can force a timeout Exceptions if allReady hasn't
return true
within timeout
It will trigger a rebuild if this state changes
-
build(BuildContext context)
→ Widget
-
Describes the part of the user interface represented by this widget.
inherited
-
deactivate()
→ void
-
Called when this object is removed from the tree.
inherited
-
debugFillProperties(DiagnosticPropertiesBuilder properties)
→ void
-
Add additional properties associated with the node.
inherited
-
didChangeDependencies()
→ void
-
Called when a dependency of this State object changes.
inherited
-
didUpdateWidget(covariant TState oldWidget)
→ void
-
Called whenever the widget configuration changes.
inherited
-
dispose()
→ void
-
Called when this object is removed from the tree permanently.
inherited
-
get<T extends Object>({String? instanceName, dynamic param1, dynamic param2})
→ T
-
this is an ugly hack so that you don't get a warning in the statefulwidget
all the following functions can be called inside the build function but also
the mixin takes care that everything is correctly disposed.
retrieves or creates an instance of a registered type
t
depending on the registration
function used for this type or based on a name.
for factories you can pass up to 2 parameters param1,param2
they have to match the types
given at registration with registerfactoryparam()
-
getAsync<T extends Object>({String? instanceName, dynamic param1, dynamic param2})
→ Future<T>
-
like get but for async registrations
-
getX<T extends Object, R>(R accessor(T?), {String? instanceName})
→ R
-
like get but with an additional
select
function to return a member of T
-
initState()
→ void
-
Called when this object is inserted into the tree.
inherited
-
isReady<T extends Object>({void onReady(BuildContext context)?, void onError(BuildContext context, Object? error)?, Duration? timeout, String? instanceName})
→ bool
-
returns
true
if the registered async or dependent object defined by T
and
instanceName
is ready
and call onReady
onError
handlers when the ready state is reached
you can force a timeout Exceptions if isReady hasn't
return true
within timeout
It will trigger a rebuild if this state changes
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
pushScope({void init(GetIt getIt)?, void dispose()?})
→ void
-
Pushes a new GetIt-Scope. After pushing it executes
init
where you can register
objects that should only exist as long as this scope exists.
Can be called inside the build
method method of a StatelessWidget
.
It ensures that it's only called once in the lifetime of a widget.
When the widget is destroyed the scope too gets destroyed after dispose
is executed. If you use this function and you have registered your objects with
an async disposal function, that functions won't be awaited.
I would recommend doing pushing and popping from your business layer but sometimes
this might come in handy
-
reassemble()
→ void
-
Called whenever the application is reassembled during debugging, for
example during hot reload.
inherited
-
rebuildOnScopeChanges()
→ void
-
Will triger a rebuild of the Widget if any new GetIt-Scope is pushed or popped
This function will return
true
if the change was a push otherwise false
If no change has happend the return value will be null
-
registerFutureHandler<T extends Object, R>(Future<R> select(T), void handler(BuildContext context, AsyncSnapshot<R?> newValue, void cancel()), {R? initialValue, String? instanceName})
→ void
-
registers a
handler
for a Future
exactly once on the first build
and unregisters is when the widget is destroyed.
This handler will only called once when the Future
completes.
select
allows you to register the handler to a member of the of the Object
stored in GetIt. If the object itself if the Future
pass (x)=>x
here
If you pass initialValue
your passed handler will be executes immediately
with that value.
All handler get passed in a cancel
function that allows to kill the registration
from inside the handler.
if the Future has completed handler
will be called every time until
the handler calls cancel
or the widget is destroyed
-
registerHandler<T extends Object, R>(ValueListenable<R> select(T), void handler(BuildContext context, R newValue, void cancel()), {bool executeImmediately = false, String? instanceName})
→ void
-
registers a
handler
for a ValueListenable
exactly once on the first build
and unregisters is when the widget is destroyed.
select
allows you to register the handler to a member of the of the Object
stored in GetIt. If the object itself if the ValueListenable
pass (x)=>x
here
If you set executeImmediately
to true
the handler will be called immediately
with the current value of the ValueListenable
.
All handler get passed in a cancel
function that allows to kill the registration
from inside the handler.
-
registerStreamHandler<T extends Object, R>(Stream<R> select(T), void handler(BuildContext context, AsyncSnapshot<R> newValue, void cancel()), {R? initialValue, String? instanceName})
→ void
-
registers a
handler
for a Stream
exactly once on the first build
and unregisters is when the widget is destroyed.
select
allows you to register the handler to a member of the of the Object
stored in GetIt. If the object itself if the ValueListenable
pass (x)=>x
here
If you pass initialValue
your passed handler will be executes immediately
with that value
As Streams can emit an error, you can register an optional errorHandler
All handler get passed in a cancel
function that allows to kill the registration
from inside the handler.
-
registerValueListenableHandler<T extends Object, R>(ValueListenable<R> select(T), void handler(BuildContext context, R newValue, void cancel()), {bool executeImmediately = false, String? instanceName})
→ void
-
-
setState(VoidCallback fn)
→ void
-
Notify the framework that the internal state of this object has changed.
inherited
-
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style})
→ DiagnosticsNode
-
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString({DiagnosticLevel minLevel = DiagnosticLevel.info})
→ String
-
A string representation of this object.
inherited
-
toStringShort()
→ String
-
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
-
watch<T extends ValueListenable<R>, R>({T? target, String? instanceName})
→ R
-
To observe
ValueListenables
like get but it also registers a listener to T
and
triggers a rebuild every time T
.value changes
If target
is not null whatch will observe this Object instead of
looking inside GetIt
-
watchFuture<T extends Object, R>(Future<R> select(T), R initialValue, {String? instanceName, bool preserveState = true})
→ AsyncSnapshot<R?>
-
awaits the
Future
returned by select
and triggers a rebuild as soon
as the Future
completes. After that it returns
an AsyncSnapshot
with the received data from the Future
When you call watchFuture a second time on the same Future
it will
return the last received data but not observe the Future a another time.
To be able to use watchStream inside a build
function
we have to pass initialValue
so that it can return something before
the Future
has completed
if select
returns a different Future
than on the last call, watchFuture
will ignore the completion of the previous Future and observe the completion
of the new Future.
preserveState
determines then if the new initial value should be the last
value of the previous stream or again initialValue
-
watchOnly<T extends Listenable, R>(R only(T), {String? instanceName})
→ R
-
like watch but for simple
Listenable
objects.
It only triggers a rebuild when the value that
only
returns changes. With that you can react to changes of single members
of T
-
watchStream<T extends Object, R>(Stream<R> select(T), R initialValue, {String? instanceName, bool preserveState = true})
→ AsyncSnapshot<R>
-
subscribes to the
Stream
returned by select
and returns
an AsyncSnapshot
with the latest received data from the Stream
Whenever new data is received it triggers a rebuild.
When you call watchStream a second time on the same Stream
it will
return the last received data but not subscribe another time.
To be able to use watchStream inside a build
function we have to pass
initialValue
so that it can return something before it has received the first data
if select
returns a different Stream than on the last call, watchStream
will cancel the previous subscription and subscribe to the new stream.
preserveState
determines then if the new initial value should be the last
value of the previous stream or again initialValue
-
watchX<T extends Object, R>(ValueListenable<R> select(T), {String? instanceName})
→ R
-
like watch but it only triggers a rebuild when the value of
the
ValueListenable
, that the function select
returns changes
useful if the ValueListenable
is a member of your business object T
-
watchXOnly<T extends Object, Q extends Listenable, R>(Q select(T), R only(Q listenable), {String? instanceName})
→ R
-
a combination of watchX and watchOnly for simple
Listenable
members Q
of your object T