颤抖:从其兄弟中获取窗口小部件的屏幕截图 [英] flutter: taking screenshots of a widget from its sibling
问题描述
我有一个视图,有两个孩子Widget A和Widget B并排站立.窗口小部件B有一个按钮,可触发窗口小部件A上的屏幕截图,
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,
,但指的是诸如这个,似乎屏幕捕获的实现必须保留在小部件A中.因此,小部件B中的按钮回调需要与小部件A对话.由于这两个都是有状态小部件,因此我发现B很难调用A在其状态内的功能.
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.
各种提供程序和herintedWidget机制似乎可以很好地处理父级到子级状态传播,但是我不清楚如何处理同级.
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.
有什么想法吗?
推荐答案
按照@pskink的提示回答此问题:
To answer this question as per @pskink 's tip:
只需将 GlobalKey
用作全局可访问变量,例如Widget A的静态成员,那么我们就可以在树中的任何地方引用A的上下文.
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.
这篇关于颤抖:从其兄弟中获取窗口小部件的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!