preWarm static method
Pre-warms the shaders for this effect.
Implementation
static Future<void> preWarm() async {
if (_cachedProgram != null || _isPreparing) return;
_isPreparing = true;
const path =
'packages/flutter_liquid_glass_widgets/shaders/interactive_indicator.frag';
const testPath = 'shaders/interactive_indicator.frag';
try {
ui.FragmentProgram program;
try {
program = await ui.FragmentProgram.fromAsset(path);
} catch (_) {
// Fallback for unit tests where package prefix may not be resolved
program = await ui.FragmentProgram.fromAsset(testPath);
}
_cachedProgram = program;
// Create a 1x1 transparent dummy image to satisfy sampler index 0.
// toImageSync (not toImage) — synchronous, consistent with
// LightweightLiquidGlass.preWarm(). For a 1×1 image the GPU cost
// is negligible and we avoid a 1-frame async initialization delay.
final recorder = ui.PictureRecorder();
Canvas(recorder);
final picture = recorder.endRecording();
_dummyImage = picture.toImageSync(1, 1);
picture.dispose();
} catch (e) {
debugPrint('[GlassEffect] Pre-warm failed: $e');
} finally {
_isPreparing = false;
}
}