Skip to content

Crash when recreating NodeEditor widget with the same controller #9

@ipr-fredrik2

Description

@ipr-fredrik2

I have a page in my application that builds a NodeEditor, but I retain the controller for it in a global state.

If I rebuild the NodeEditor (the second time) with the previously used controller (that has a bunch of nodes and connections), I get a crash in render_info.dart:16:

/// get the position of object in the screen, correcting by the position of
/// vertical and horizontal scroll
Offset getObjectPosition(NodeEditorController controller, GlobalKey key) {
  var obj = key.currentContext?.findRenderObject();
  final RenderBox stackRenderBox = obj as RenderBox; /// <-- obj IS NULL HERE!

  // fix position by scroll position
  return stackRenderBox.localToGlobal(Offset.zero) -
      controller.stackPos! +
      Offset(controller.horizontalScrollController.offset,
          controller.verticalScrollController.offset);
}

Seems like its due to the global key being recreated when the pins are being recreated (in _InPortWidgetState, when you call controller.addInPort).

Is this a bug, or am I using the library wrong? It works phenomenally otherwise, thank you for creating another fantastic flutter package!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions