Flutter 如何知道无状态小部件在视口中是否可见?

Flutter 如何知道无状态小部件在视口中是否可见?,flutter,Flutter,在我的项目中,我有一个带有按钮的屏幕。当用户点击按钮时,我调用库/依赖项为我拍摄图像,然后当用户单击该屏幕的“完成”按钮时,它返回该图像的路径 我知道,如果我将无状态小部件转换为有状态小部件,那么我就能够访问有状态类的mounted属性。但我的问题是,对于无状态小部件是否有类似的情况,或者是否有任何方法可以看到小部件(我的场景)是否对用户可见 class LandingScreen extends StatelessWidget { void _onImageReceived() async

在我的项目中,我有一个带有按钮的屏幕。当用户点击按钮时,我调用库/依赖项为我拍摄图像,然后当用户单击该屏幕的“完成”按钮时,它返回该图像的路径

我知道,如果我将无状态小部件转换为有状态小部件,那么我就能够访问有状态类的
mounted
属性。但我的问题是,对于无状态小部件是否有类似的情况,或者是否有任何方法可以看到小部件(我的场景)是否对用户可见

class LandingScreen extends StatelessWidget {
  void _onImageReceived() async {
    print('Running EdgeDetection...');
    try {
      final String path = await EdgeDetection.detectEdge;
      print('The saved image path is: $path');
    } on PlatformException {
      print('Failed to get cropped image path');
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return; // <= This is for Stateful widget that doesn't work in the Stateless widget
  }
}
class LandingScreen扩展了无状态小部件{
void _onImageReceived()异步{
打印('运行边缘检测…');
试一试{
最终字符串路径=wait EdgeDetection.detectEdge;
打印('保存的图像路径为:$path');
}平台异常{
打印('无法获取裁剪图像路径');
}
//如果在异步平台运行时从树中删除了小部件
//消息正在传输中,我们希望放弃回复而不是呼叫
//设置state以更新我们不存在的外观。
if(!mounted)return;//查看此项以获取屏幕上的位置,然后与屏幕的高度进行比较。