initialize static method
Initializes the Liquid Glass library.
This should be called in your main() function:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LiquidGlassWidgets.initialize();
runApp(LiquidGlassWidgets.wrap(const MyApp()));
}
Accessibility
By default, system Reduce Motion and Reduce Transparency are respected automatically — no extra setup needed. To opt out globally (e.g. for a game where full glass fidelity is intentional):
await LiquidGlassWidgets.initialize(respectSystemAccessibility: false);
A GlassAccessibilityScope placed in the widget tree always takes precedence over this flag, allowing per-subtree overrides.
Tasks performed:
- Pre-warms/precaches the lightweight fragment shader.
- Pre-warms the interactive indicator shader (for custom refraction).
- Pre-warms Impeller rendering pipeline (iOS/Android/macOS).
Implementation
static Future<void> initialize({
bool respectSystemAccessibility = true,
}) async {
LiquidGlassWidgets.respectSystemAccessibility = respectSystemAccessibility;
debugPrint('[LiquidGlass] Initializing library...');
// 1. Pre-warm shaders
// This is the most critical step to prevent the "white flash" on Skia/Web
await Future.wait([
LightweightLiquidGlass.preWarm(),
GlassEffect.preWarm(),
_warmUpImpellerPipeline(),
]);
debugPrint('[LiquidGlass] Initialization complete.');
}