layerEffects function
style.effects as a CSS filter chain on the whole layer (web ImageEngine, unified effects
stack), applied in file order: blur blurs, and on non-text layers drop-shadow and glow
cast the layer's own silhouette (CSS drop-shadow()), not its box. On text layers those two
are text shadows (textEffectShadows) and are skipped here.
Implementation
Widget layerEffects(Widget child, Map<String, dynamic> style, OimPalette? palette, {required bool isText, double unit = 1}) {
final effects = style['effects'];
if (effects is! List) return child;
num n(dynamic v, num d) => v is num ? v : d;
var w = child;
Widget cast(Widget src, Color c, Offset offset, double blurRadius) {
// drop-shadow() blur radius is twice the Gaussian sigma (unlike blur()).
Widget s = ColorFiltered(colorFilter: ColorFilter.mode(c, BlendMode.srcIn), child: src);
if (blurRadius > 0) {
s = ImageFiltered(imageFilter: ui.ImageFilter.blur(sigmaX: blurRadius / 2, sigmaY: blurRadius / 2, tileMode: TileMode.decal), child: s);
}
return Stack(fit: StackFit.passthrough, clipBehavior: Clip.none, children: [Transform.translate(offset: offset, child: s), src]);
}
for (final e in effects) {
if (e is! Map || e['enabled'] == false) continue;
final type = e['type'];
if (type == 'blur') {
final r = n(e['radius'], 8).toDouble() * unit;
// CSS blur() takes the standard deviation itself.
if (r > 0) w = ImageFiltered(imageFilter: ui.ImageFilter.blur(sigmaX: r, sigmaY: r, tileMode: TileMode.decal), child: w);
} else if (isText) {
continue;
} else if (type == 'drop-shadow') {
final c = resolveColor(e['colorRole'] ?? style['shadowColorRole'], e['color'] ?? 'rgba(0, 0, 0, 0.35)', palette) ?? const Color(0x59000000);
w = cast(w, c, Offset(n(e['x'], 0).toDouble(), n(e['y'], 4).toDouble()) * unit, n(e['blur'], 12).toDouble() * unit);
} else if (type == 'glow') {
final r = (e['radius'] is num && e['radius'] != 0 ? e['radius'] as num : 16).toDouble() * unit;
final c = resolveColor(e['colorRole'] ?? style['effectColorRole'], e['color'] ?? '#f59e0b', palette) ?? const Color(0xFFF59E0B);
w = cast(cast(w, c, Offset.zero, r * 0.4), c, Offset.zero, r);
}
}
return w;
}