How to know if a widget is visible within a viewport?

前端 未结 2 2151
梦谈多话
梦谈多话 2020-11-30 03:21

I have a view that consists of a Scaffold and a single ListView in its body, each children of the list is a different widget that represents variou

2条回答
  •  野性不改
    2020-11-30 03:51

    https://pub.dev/packages/visibility_detector provides this functionality with its VisibilityDetector widget that can wrap any other Widget and notify when the visible area of the widget changed:

    VisibilityDetector(
       key: Key("unique key"),
       onVisibilityChanged: (VisibilityInfo info) {
           debugPrint("${info.visibleFraction} of my widget is visible");
       },
       child: MyWidgetToTrack());
    )
    

提交回复
热议问题