flutter: taking screenshots of a widget from its sibling

时光总嘲笑我的痴心妄想 提交于 2021-01-29 06:17:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!