widgetsWithScreenPositions method
Currently rendered widgets with their position info
Implementation
List<ChildInfo> widgetsWithScreenPositions({bool forceRebuild = false}) {
if (!_init) return [];
if (_focusChildOnBuild != null) {
// if this is the first build, focus on the child if set
focusOnChild(_focusChildOnBuild!, animate: false);
_focusChildOnBuild = null;
}
// _renderCacheDirty depends on _markDirty + other stuff
if (!_renderCacheDirty && !forceRebuild) {
// if the render cache is not dirty, we can use the cached result
return _lastRenderedWidgets;
}
_lastProcessedOffset = _gsTopLeftOffset;
_lastProcessedScale = _scale;
_markDirty = false;
final idsToBuild = _childrenWithinBuildArea(_gsCenter, buildExtent);
// do the needed callbacks
if (onWidgetEnteredRender != null || onWidgetExitedRender != null) {
final newRenderedWidgets = idsToBuild.toSet();
final exitedWidgets = _renderedWidgets.difference(newRenderedWidgets);
final enteredWidgets = newRenderedWidgets.difference(_renderedWidgets);
Future.microtask(() {
// so that the build is not blocked
for (final id in exitedWidgets) {
onWidgetExitedRender?.call(id);
}
for (final id in enteredWidgets) {
onWidgetEnteredRender?.call(id);
}
});
}
_renderedWidgets = idsToBuild.toSet();
return _lastRenderedWidgets = idsToBuild.map((id) {
final item = _children[id]!;
final ssPosition = gsToSs(item.gsPosition, _gsTopLeftOffset, _scale);
var child = item.widget;
if (debug) {
child = _Debug(
key: ValueKey<String>(id),
id: id,
gs: item.gsPosition,
ss: ssPosition,
child: child,
);
}
return ChildInfo(
id: id,
gsPosition: item.gsPosition,
ssPosition: ssPosition,
child: child,
);
}).toList();
}