Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same key is being used by multiple widgets in GraphView.dart #85

Open
VikasJilla opened this issue May 23, 2022 · 2 comments
Open

Same key is being used by multiple widgets in GraphView.dart #85

VikasJilla opened this issue May 23, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@VikasJilla
Copy link

Hi,

I have observed that in GraphView.dart, when we pass a key to GraphView, you are passing it to both super constructor, as well as the widget being returned in build method. I think this should not be done. Because of this we are getting an issue as below:

The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [LabeledGlobalKey<State<GraphView>>#f63ba] was used by multiple widgets. The parents of those widgets were:
- GraphView-[LabeledGlobalKey<State<GraphView>>#f63ba](state: _GraphViewState#22b82)
- KeyedSubtree-[GlobalKey#0985f]
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack:
#0      BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/framework.dart:2868:13)
#1      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:614:13)

Please resolve this as soon as possible. Please let me know if there is something I missed.

@nabil6391
Copy link
Owner

Hi, By any chance do you haev any example code that I can look into. Like for example whats the keys you are using. You do have to ensure that there are no duplicate keys for the nodes

@nabil6391 nabil6391 added the bug Something isn't working label Jul 26, 2022
VikasJilla added a commit to VikasJilla/graphview that referenced this issue Oct 15, 2022
key is being passed to super class aswell as to other widgets in build method leading to this [issue](nabil6391#85).
@VikasJilla
Copy link
Author

@nabil6391 below is the sample code that was leading to the error.

final GlobalKey _graphViewKey = GlobalKey<State<GraphView>>();
 GraphView(
        key: _graphViewKey,
        graph: graph,
        algorithm: walkerAlgorithm!,
        animated: true,
        paint: Paint()
          ..color = AppColors.relationsGreyColor
          ..strokeWidth = 1
          ..style = PaintingStyle.stroke,
        builder: (Node node) {
          return buildNode(node);
        },
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants