SafeRenderManager class
A class that manages the top-level rendering of a ReactElement into a given node, with support for safely rendering/updating via render and safely unmounting via tryUnmount.
Content is also unmounted when this object is disposed.
This is useful in cases where react_dom.render or react_dom.unmountComponentAtNode may or may not be called from React events or lifecycle methods, which can have undesirable/unintended side effects.
For instance, calling react_dom.unmountComponentAtNode can unmount a component while an event is being propagated through a component, which normally would never happen. This could result in null errors in the component as the event logic continues.
SafeRenderManager uses a helper component under the hood to manage the rendering of content via Component state changes, ensuring that the content is mounted/unmounted as it normally would be.
Constructors
- SafeRenderManager({Element? mountNode, bool autoAttachMountNode = false})
Properties
- autoAttachMountNode → bool
-
Whether to automatically add mountNode to the document body when
rendered, and remove it when unmounted.
final
- contentRef ↔ dynamic
-
The ref to the component rendered by render.
getter/setter pair
-
didDispose
→ Future<
Null> -
A Future that will complete when this object has been disposed.
no setterinherited
- disposableTypeName → String
-
A type name, similar to runtimeType but intended to work
with minified code.
no setterinherited
- disposalTreeSize → int
-
The total size of the disposal tree rooted at the current Disposable
instance.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this object has been disposed.
no setterinherited
- isLeakFlagSet → bool
-
Whether the leak flag for this object has been set.
no setterinherited
- isOrWillBeDisposed → bool
-
Whether the disposal of this object has been requested, is in progress, or
is complete.
no setterinherited
- mountNode → Element
-
The mount node for content rendered by render.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
awaitBeforeDispose<
T> (Future< T> future) → Future<T> -
Add
future
to a list of futures that will be awaited before the object is disposed.inherited -
dispose(
) → Future< Null> -
Dispose of the object, cleaning up to prevent memory leaks.
inherited
-
flagLeak(
[String? description]) → void -
Flag the object as having been disposed in a way that allows easier
profiling.
inherited
-
getManagedDelayedFuture<
T> (Duration duration, T callback()) → Future< T> -
Creates a Future that will complete, with the value
returned by
callback
, after the given amount of time has elapsed.inherited -
getManagedDisposer(
Disposer disposer) → ManagedDisposer -
Automatically handle arbitrary disposals using a callback.
inherited
-
getManagedPeriodicTimer(
Duration duration, void callback(Timer timer)) → Timer -
Creates a periodic Timer that will be cancelled if active
upon disposal.
inherited
-
getManagedTimer(
Duration duration, void callback()) → Timer -
Creates a Timer instance that will be cancelled if active
upon disposal.
inherited
-
listenToStream<
T> (Stream< T> stream, void onData(T event), {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription<T> -
Returns a StreamSubscription which handles events from the stream using
the provided
onData
,onError
andonDone
handlers.inherited -
manageAndReturnTypedDisposable<
T extends Disposable> (T disposable) → T -
Automatically dispose another object when this object is disposed.
inherited
-
manageCompleter<
T> (Completer< T> completer) → Completer<T> -
Ensure that a completer is completed when the object is disposed.
inherited
-
manageDisposable(
Disposable disposable) → void -
inherited
-
manageStreamController(
StreamController controller) → void -
Automatically cancel a stream controller when this object is disposed.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDispose(
) → Future< Null> - Callback to allow arbitrary cleanup on dispose.
-
onWillDispose(
) → Future< Null> -
Callback to allow arbitrary cleanup as soon as disposal is requested (i.e.
dispose is called) but prior to disposal actually starting.
inherited
-
render(
ReactElement? content) → void -
Renders
content
into mountNode, chaining existing callback refs to provide access to the rendered component via contentRef. -
toString(
) → String -
A string representation of this object.
inherited
-
tryUnmount(
{void onMaybeUnmounted(bool isUnmounted)?}) → void -
Attempts to unmount the rendered component, calling
onMaybeUnmounted
with whether the component was actually unmounted.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited