wrapByVisibilityDetector method
wrap widget by VisibilityDetector
that can know if child
is visible
Implementation
Widget wrapByVisibilityDetector(int index, Widget child) {
return VisibilityDetector(
key: ValueKey(index.toString()),
onVisibilityChanged: (VisibilityInfo info) {
final visibleFraction = info.visibleFraction;
if (isForward) {
visibleFraction == 0
? indexTreeSet.remove(index)
: indexTreeSet.add(index);
} else {
visibleFraction == 1.0
? indexTreeSet.add(index)
: indexTreeSet.remove(index);
}
if (indexTreeSet.isNotEmpty) {
_tocController?.onIndexChanged(indexTreeSet.first);
}
},
child: child,
);
}