检查窗口小部件是否在屏幕上

时间:2020-04-13 12:59:13

标签: flutter widget

有没有一种方法可以检测窗口小部件是否在屏幕上/是否在应用程序的任何位置可见。例如,在TabBarPageView中。

我已经知道我可以使用小部件的build方法来检测到这种情况,但这会导致一些非常奇怪的行为,即有时已经构建了小部件,并且当用户导航到屏幕时没有任何反应。

那么有没有办法对整个应用程序执行此操作?

1 个答案:

答案 0 :(得分:0)

也许您可以尝试使用诸如全局密钥之类的小部件密钥

data () { return { eb: { 'attachmentList': [] } } }, methods: { addAttachment() { var a = {'typeId': '', 'description': '', 'file': ''}; this.eb.attachmentList.push(a); }, selectFile( index, e ){ this.eb.attachmentList[index].file = e.target.files[0]; }, delAttachment( a, index ) { this.eb.attachmentList.splice(index, 1); //and delete this attachment from database } }

他们将其传递给您想知道状态的小部件