You can use any class that implements Disposable and it will be disposed when the widget is removed from the widget tree. You also don't need to provide a dispose function for the ScopedRef.
class Counter implements Disposable {
final value = signal(0);
final doubled = computed(() => value.value * 2);
@override
void dispose() {
value.dispose();
doubled.dispose();
}
}
final counterRef = Ref.scoped((_) => Counter());
Lite Ref
Lite Ref is a simple way to provide disposable objects to your widgets.
You can use any class that implements
Disposable
and it will be disposed when the widget is removed from the widget tree. You also don't need to provide adispose
function for the ScopedRef.