effectiveElementOpacity function
Returns the effective opacity contributed by the element's ancestors.
Implementation
double effectiveElementOpacity(Element element) {
var opacity = 1.0;
element.visitAncestorElements((ancestor) {
final renderObject = ancestor.renderObject;
if (renderObject is RenderOpacity) {
opacity *= renderObject.opacity;
} else if (renderObject != null &&
renderObject.runtimeType.toString() == 'RenderAnimatedOpacity') {
try {
final animatedOpacity = (renderObject as dynamic).opacity;
if (animatedOpacity is Animation<double>) {
opacity *= animatedOpacity.value;
} else if (animatedOpacity is double) {
opacity *= animatedOpacity;
}
} catch (_) {
// Keep the opacity already collected from other ancestors.
}
}
return opacity > 0.01;
});
return opacity;
}