问题
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?
回答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.
来源:https://stackoverflow.com/questions/63049828/flutter-taking-screenshots-of-a-widget-from-its-sibling