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?

kakyo
  • 10,460
  • 14
  • 76
  • 140
  • 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 '20 at 08:26
  • @pskink Thanks. Indeed, I forgot I could use global key as a static var! – kakyo Jul 23 '20 at 08:52

1 Answers1

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.

kakyo
  • 10,460
  • 14
  • 76
  • 140