← Back to posts Cover image for Flutter UI Kits: Building Beautiful, Performant Interfaces with Frosted Glass and Fluid Design

Flutter UI Kits: Building Beautiful, Performant Interfaces with Frosted Glass and Fluid Design

· 5 min read
Weekly Digest

The Flutter news you actually need

No spam, ever. Unsubscribe in one click.

Chris
By Chris

Building a Flutter app that feels premium and modern often means incorporating sophisticated visual effects. Two of the most sought-after—and tricky to implement—are the frosted glass blur and fluid, pointer-driven animations. The challenge is clear: how do we create these beautiful interfaces without grinding our app’s performance to a halt?

The typical approach, using heavy widget trees with BackdropFilter or complex AnimatedContainer builds, can quickly lead to jank, especially on lower-end devices or during rapid interactions. The key to unlocking both beauty and smoothness lies in leveraging the right tools: custom painters, fragment shaders, and a deep understanding of Flutter’s rendering pipeline.

Let’s break down how to build these effects from the ground up, focusing on performance and customization.

Crafting a Performant Frosted Glass Effect

The frosted glass (or “glassmorphism”) effect relies on blurring the content behind a translucent panel. While BackdropFilter exists, it’s notoriously expensive because it blurs the entire layer behind it, which can be re-computed frequently. A more performant strategy is to capture a static snapshot of the background and blur only that.

Here’s a custom widget that uses an ImageFilter on a selectively painted background:

import 'dart:ui';
import 'package:flutter/material.dart';

class FrostedPanel extends StatelessWidget {
  const FrostedPanel({
    super.key,
    required this.child,
    this.blurAmount =与合作5.0,
    this.borderRadius = 20.0,
  });

  final Widget child;
  final double blurAmount;
  final double borderRadius;

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(borderRadius),
      child: Stack(
        children: [
          // 1. Background Blur Layer
          Positioned.fill(
            child: BackdropFilter(
              filter: ImageFilter.blur(
                sigmaX: blurAmount,
                sigmaY: blurAmount,
              ),
              child: Container(color: Colors.transparent),
            ),
          ),
          // 2. Lightening/Vignette Layer for better contrast
          Positioned.fill(
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(borderRadius),
                color: Colors.white.withOpacity(0.15),
                border: Border.all(
                  color: Colors.white.withOpacity(0.2),
                  width: 1.0,
                ),
              ),
            ),
          ),
          // 3. Content on top
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: child,
          ),
        ],
      ),
    );
  }
}

// Usage
FrostedPanel(
  blurAmount: 8.0,
  child: const Text(
    'Hello, Frosted World!',
    style: TextStyle(color: Colors.white, fontSize: 24),
  ),
)

Common Pitfall & Optimization: Using BackdropFilter in a scrolling list or an area that animates frequently is a recipe for dropped frames. For dynamic backgrounds, consider using a RepaintBoundary to capture the background as a texture once, then applying the blur to that static image. This is more complex but far more efficient.

// Simplified concept for pre-capturing background
final _repaintKey = GlobalKey();
final _imageReady = ValueNotifier<bool>(false);
ui.Image? _capturedImage;

void _captureBackground() {
  // BuildContext and RenderBox lookup needed here
  // RenderRepaintBoundary boundary = _repaintKey.currentContext?.findRenderObject() as RenderRepaintBoundary;
  // _capturedImage = await boundary.toImage();
  // _imageReady.value = true;
}

// Then, in your widget tree, paint the captured image with an ImageFilter.

Implementing Fluid, Shader-Based Animations

For truly fluid, custom visual transitions (like a noise-based wipe or a morphing effect), the most powerful tool is a custom fragment shader. Shaders run on the GPU, making them incredibly efficient for per-pixel operations. Flutter lets us write these in GLSL and load them via the dart:ui library.

Let’s create a simple gradient wipe effect controlled by pointer position.

Step 1: Write the Fragment Shader (shaders/fluid_wipe.frag):

#version 460 core
#include <flutter/runtime_effects.glsl>

uniform vec2 uSize;
uniform float uProgress;
out vec4 fragColor;

void main() {
  vec2 uv = FlutterFragCoord().xy / uSize;

  // Create a diagonal gradient
  float gradient = (uv.x + uv.y) / 2.0;

  // Apply progress to create a wipe threshold
  float threshold = step(uProgress, gradient);

  // Mix between two colors based on the threshold
  vec4 colorA = vec4(0.2, 0.5, 1.0, 1.0); // Blue
  vec4 colorB = vec4(1.0, 0.7, 0.2, 1.0); // Orange
  fragColor = mix(colorA, colorB, threshold);
}

Step 2: Load the Shader and Create a Custom Painter in Dart:

import 'dart:ui';
import 'package:flutter/material.dart';

class FluidWipePainter extends CustomPainter {
  FluidWipePainter(this.progress, this.shader);

  final double progress;
  final FragmentShader shader;

  @override
  void paint(Canvas canvas, Size size) {
    // Set the uniform values for the shader
    shader.setFloat(0, size.width);
    shader.setFloat(1, size.height);
    shader.setFloat(2, progress.clamp(0.0, 1.0));

    // Paint a rectangle that executes the shader
    final paint = Paint()..shader = shader;
    canvas.drawRect(Offset.zero & size, paint);
  }

  @override
  bool shouldRepaint(FluidWipePainter oldDelegate) {
    return oldDelegate.progress != progress;
  }
}

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

  @override
  State<FluidDemoWidget> createState() => _FluidDemoWidgetState();
}

class _FluidDemoWidgetState extends State<FluidDemoWidget> {
  FragmentShader? _shader;
  double _progress = 0.0;

  @override
  void initState() {
    super.initState();
    _loadShader();
  }

  Future<void> _loadShader() async {
    final program = await FragmentProgram.fromAsset('shaders/fluid_wipe.frag');
    _shader = program.fragmentShader();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onPanUpdate: (details) {
        setState(() {
          // Update progress based on horizontal drag
          _progress += details.delta.dx / 300;
          _progress = _progress.clamp(0.0, 1.0);
        });
      },
      child: Container(
        color: Colors.grey[900],
        child: CustomPaint(
          painter: _shader != null
              ? FluidWipePainter(_progress, _shader!)
              : null,
          size: Size.infinite,
        ),
      ),
    );
  }
}

Why This Approach Wins: The animation logic (updating _progress) is cheap and happens on the CPU. The heavy lifting of calculating the color for every pixel based on that single uniform value is offloaded to the GPU via the shader, resulting in silky-smooth 60fps animations even on complex gradients or noise patterns.

Putting It All Together

When building your UI kit, separate concerns: use optimized widget-based solutions for static glass effects (with careful use of RepaintBoundary), and reserve custom shaders for dynamic, per-pixel animations. Always profile your app using Flutter DevTools’ performance overlay to ensure your UI remains smooth.

Remember, the goal is to create an immersive experience. Start with these foundational techniques—a robust frosted panel and a shader-driven animation—and you’ll have the core components to build an entire library of beautiful, performant UI elements that feel fluid and responsive.

This blog is produced with the assistance of AI by a human editor. Learn more

Related Posts

Cover image for Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Developers frequently struggle with persistent storage in Flutter, especially when dealing with OS-level backups and app reinstalls. This post will clarify the nuances of different storage solutions like `SharedPreferences`, `path_provider`, and `flutter_secure_storage`, focusing on how to correctly manage data lifetimes (per-install vs. per-user) and avoid issues like device IDs migrating to new phones or data being unexpectedly backed up.

Cover image for Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Flutter's `ImageFiltered` can cause significant lag when blurring large or frequently changing content like text. This post will explain the performance bottlenecks, provide solutions like caching blurred outputs with `RepaintBoundary` or `SnapshotWidget`, and offer practical tips to ensure smooth UI effects without sacrificing frame rates.