setSelection method Null safety

  1. @protected
bool setSelection(
  1. Object? object,
  2. [String? groupName]
)

Set the WidgetInspector selection to the specified object if it is a valid object to set as the inspector selection.

Returns true if the selection was changed.

The groupName parameter is not needed but is specified to regularize the API surface of methods called from the Flutter IntelliJ Plugin.

Implementation

@protected
bool setSelection(Object? object, [ String? groupName ]) {
  if (object is Element || object is RenderObject) {
    if (object is Element) {
      if (object == selection.currentElement) {
        return false;
      }
      selection.currentElement = object;
      developer.inspect(selection.currentElement);
    } else {
      if (object == selection.current) {
        return false;
      }
      selection.current = object! as RenderObject;
      developer.inspect(selection.current);
    }
    if (selectionChangedCallback != null) {
      if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle) {
        selectionChangedCallback!();
      } else {
        // It isn't safe to trigger the selection change callback if we are in
        // the middle of rendering the frame.
        SchedulerBinding.instance.scheduleTask(
          selectionChangedCallback!,
          Priority.touch,
        );
      }
    }
    return true;
  }
  return false;
}