RaiiDisposeable class
A lifecycle implementation that wraps a dispose callback and manages its lifecycle.
This class is the core implementation behind the RAII pattern used by various Flutter extensions. It provides a way to attach any disposable resource to a RaiiLifecycleAware object, ensuring proper cleanup when the lifecycle ends.
Example:
// Direct usage (though extensions are preferred)
final controller = TextEditingController();
RaiiDisposeable.withLifecycle(
lifecycleAware,
dispose: controller.dispose,
debugLabel: 'TextController',
);
// More complex disposal logic
RaiiDisposeable.withLifecycle(
lifecycleAware,
dispose: () {
controller.removeListener(onChanged);
controller.dispose();
},
debugLabel: 'TextControllerWithListener',
);
- Mixed-in types
Constructors
- RaiiDisposeable.withLifecycle(RaiiLifecycleAware lifecycleAware, {required VoidCallback dispose, String? debugLabel})
-
Creates a RaiiDisposeable and attaches it to the provided
lifecycleAware
.
Properties
- debugLabel → String?
-
Optional label for debugging purposes.
final
- dispose → VoidCallback
-
The callback to execute when disposing of the resource.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
disposeLifecycle(
) → void -
Disposes of any resources held by this object.
override
-
initLifecycle(
) → void -
Initializes the lifecycle of this object.
override
-
isLifecycleMounted(
) → bool -
Returns whether this object's lifecycle is currently mounted.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited