Skip to main content

glass 2.5.0 copy "glass: ^2.5.0" to clipboard
glass: ^2.5.0 copied to clipboard

Turn any widget into frosted glass or Apple-style liquid glass (refraction, rim light, tint) with a single asGlass() call.

example/lib/main.dart

// Flutter 3.50 deprecates material.dart; material_ui does not exist on the minimum Flutter 3.29.
// ignore_for_file: deprecated_member_use
import 'package:flutter/material.dart';
import 'package:glass/glass.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool effectEnabled = true;
  bool liquid = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(image: AssetImage('images/demo.png')),
          ),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                TextButton(
                  onPressed:
                      () => setState(() => effectEnabled = !effectEnabled),
                  style: TextButton.styleFrom(
                    padding: const EdgeInsets.all(200),
                  ),
                  child: const Text(
                    'Night sky',
                    style: TextStyle(color: Colors.white),
                  ),
                ).asGlass(
                  enabled: effectEnabled,
                  tintColor: Colors.transparent,
                  clipBorderRadius: BorderRadius.circular(15.0),
                  // Liquid glass needs Impeller; elsewhere it falls back to plain glass.
                  liquid: liquid ? LiquidGlass.clear : null,
                ),
                const SizedBox(height: 24),
                Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const Text(
                      'Liquid glass',
                      style: TextStyle(color: Colors.white),
                    ),
                    const SizedBox(width: 8),
                    Switch(
                      value: liquid,
                      onChanged: (value) => setState(() => liquid = value),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
136
likes
160
points
1.76k
downloads
screenshot

Documentation

API reference

Publisher

verified publisherzac.ac

Weekly Downloads

Turn any widget into frosted glass or Apple-style liquid glass (refraction, rim light, tint) with a single asGlass() call.

Repository (GitHub)
View/report issues

Topics

#glassmorphism #liquid-glass #blur #effects #ui

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on glass