findWidgetForComponent<WidgetType> static method

WidgetType findWidgetForComponent<WidgetType>(
  1. String nodeId, [
  2. Finder? superDocumentFinder
])

Finds and returns the Widget that configures the DocumentComponent with the given nodeId.

The given nodeId must exist in the SuperReader's document. The Widget that configures the give node must be of type WidgetType.

By default, this method expects a single SuperReader in the widget tree and finds it byType. To specify one SuperReader among many, pass a superDocumentFinder.

Implementation

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

  return widget as WidgetType;
}