initialize static method
Initializes platform-level resources for the Liquid Glass library.
Responsibility: async platform / engine setup only. Call once in
main() before runApp. All behavioral configuration belongs in wrap.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LiquidGlassWidgets.initialize();
runApp(LiquidGlassWidgets.wrap(const MyApp()));
}
Parameters
enablePerformanceMonitor (default true)
In debug and profile builds, the library registers a
SchedulerBinding.addTimingsCallback that watches raster durations while
GlassQuality.premium surfaces are mounted. When frames consistently
exceed the GPU budget, a single FlutterError is emitted with actionable
guidance. The monitor is automatically disabled in release builds —
zero overhead in shipped apps. Set to false to suppress it during
profiling sessions where the warning would be a false positive.
Tasks performed
- Pre-warms / precaches the lightweight fragment shader.
- Pre-warms the interactive indicator shader (custom refraction).
- Pre-warms the Impeller rendering pipeline (iOS / Android / macOS).
- Optionally registers the debug performance monitor.
Implementation
static Future<void> initialize({
bool enablePerformanceMonitor = true,
}) async {
debugPrint('[LiquidGlass] Initializing library...');
// 1. Pre-warm shaders — prevents the "white flash" on first render.
await Future.wait([
LightweightLiquidGlass.preWarm(),
GlassEffect.preWarm(),
_warmUpImpellerPipeline(),
]);
// 2. Register the debug performance monitor (no-op in release builds).
if (enablePerformanceMonitor && !kReleaseMode) {
GlassPerformanceMonitor.start();
}
debugPrint('[LiquidGlass] Initialization complete.');
}