maybeFindWidgetForComponent<WidgetType> static method

WidgetType? maybeFindWidgetForComponent<WidgetType>(
  1. String nodeId, [
  2. Finder? superEditorFinder
])

Same as findWidgetForComponent, except this method returns null when no such component is found.

Implementation

static WidgetType? maybeFindWidgetForComponent<WidgetType>(String nodeId, [Finder? superEditorFinder]) {
  final documentLayout = findDocumentLayout(superEditorFinder);
  final widget = (documentLayout.getComponentByNodeId(nodeId) as State?)?.widget;
  if (widget != null && widget is! WidgetType) {
    throw Exception("Looking for a component's widget. Expected type $WidgetType, but found ${widget.runtimeType}");
  }

  return widget as WidgetType;
}