preWarm static method

Future<void> preWarm()

Implementation

static Future<void> preWarm() async {
  if (_cachedProgram != null || _isPreparing) return;
  _isPreparing = true;
  try {
    final program = await ui.FragmentProgram.fromAsset(
      'packages/liquid_glass_widgets/shaders/interactive_indicator.frag',
    );
    _cachedProgram = program;

    if (!kIsWeb) {
      debugPrint('[GlassEffect] ✓ Shader precached (native)');
    } else {
      debugPrint('[GlassEffect] ✓ Shader program loaded (web)');
    }

    // Create a 1x1 transparent dummy image to satisfy sampler index 0
    final recorder = ui.PictureRecorder();
    final canvas = Canvas(recorder);
    canvas.drawColor(const Color(0x00000000), BlendMode.src);
    final picture = recorder.endRecording();
    _dummyImage = await picture.toImage(1, 1);
  } catch (e) {
    debugPrint('[GlassEffect] Pre-warm failed: $e');
  } finally {
    _isPreparing = false;
  }
}