Saltearse al contenido

RtStateObserver

Esta página aún no está disponible en tu idioma.

RtStateObserver is a class that provides a way to observe the lifecycle of states in Reactter.

Syntax

RtStateObserver({
void onBound(RtState state, Object instance)?,
void onUnbound(RtState state, Object instance)?,
void onCreated(RtState state)?,
void onUpdated(RtState state)?,
void onDisposed(RtState state)?,
});

The RtStateObserver class accepts these parameters:

  • onBound : (optional) Called when a state is bound to an instance.
  • onUnbound : (optional) Called when a state is unbound from an instance.
  • onCreated : (optional) Called when a state is initialized.
  • onUpdated : (optional) Called when a state undergoes a change or update.
  • onDisposed : (optional) Called when a state is disposed or cleaned up.

Usage

To use RtStateObserver , you need to instantiate it, pass the callbacks you want to use and then add it using the Rt.addObserver method, e.g.:

1
import 'package:reactter/reactter.dart';
2
3
void main() {
4
// Create a state observer with lifecycle callbacks
5
final stateObserver = RtStateObserver(
6
onBound: (state, instance) {
7
print('State($state) bound to instance($instance)');
8
},
9
onUnbound: (state, instance) {
10
print('State($state) unbound from instance($instance)');
11
},
12
onCreated: (state) {
13
print('State($state) created');
14
},
15
onUpdated: (state) {
16
print('State($state) updated');
17
},
18
onDisposed: (state) {
19
print('State($state) disposed');
20
},
21
);
22
23
// Add the state observer to Reactter's observer system
24
Rt.addObserver(stateObserver);
25
}