0

Goal

I have a view that has two children Widget A and Widget B, standing side by side. Widget B has a button that triggers a screenshot on Widget A,

Problem

but referring to questions such as this one, it seems that the implementation of screen capture must stay within Widget A. So the button callback in Widget B needs to talk to Widget A. Since both are stateful widgets, I find it difficult for B to call A's function inside its state.

The various provider and inheritedWidget mechanisms seem to handle parent-to-child state propagation nicely but it's unclear to me how to handle siblings.

Any ideas?

2
  • 2
    you can call someGlobalKey.currentContext.findRenderObject() from any place in the tree, no need for doing that from the child widget
    – pskink
    Jul 23, 2020 at 8:26
  • @pskink Thanks. Indeed, I forgot I could use global key as a static var!
    – kakyo
    Jul 23, 2020 at 8:52

1 Answer 1

1

To answer this question as per @pskink 's tip:

Just use GlobalKey as a globally accessible variable such as a static member of Widget A, then we could refer to A's context anywhere in the tree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.