getDartInstance method
T?
getDartInstance()
Returns the native Dart component associated with the mounted React composite component instance, or null if the component is not Dart based.
If you are rendering a function component using mount, calling getDartInstance will throw a
StateError
.See getInstance for more information about this limitation.
Implementation
T? getDartInstance() {
// [1] Adding an additional check for dom components here because the current behavior when `_renderedInstance` is
// a DOM component (Element) - is to return `null`. While that will most likely cause null exceptions once the
// consumer attempts to make a call on the "Dart instance" they have requested - we don't want this change
// to cause new exceptions in a scenario where the consumer was storing a null value and then simply
// not using it in their test.
if (!_isCompositeComponent && /*[1]*/!_isDomComponent) {
throw StateError(
'getDartInstance() is only supported when the rendered object is a composite (class based) component.');
}
return over_react.getDartComponent(_renderedInstance);
}