A Flutter plugin that creates a beautiful mica-like translucent effect using the device's wallpaper, similar to Windows 11's Mica material.
- Creates a blurred background effect using the device's current wallpaper
- Automatically updates when the wallpaper changes
- Supports smooth animations when transitioning between wallpapers
- Customizable blur intensity, opacity, and animation duration
- Efficient caching mechanism to improve performance
- Handles large wallpaper images with automatic downsampling
- Works on both Android and iOS
Add this to your package's pubspec.yaml file:
dependencies:
mica_background: ^0.0.1Then run:
flutter pub getImport the package:
import 'package:mica_background/mica_background.dart';Use the MicaBackground.mica() widget as a background:
import 'package:flutter/material.dart';
import 'package:mica_background/mica_background.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
// Use MicaBackground as the background
MicaBackground.mica(
animationDuration: const Duration(seconds: 1),
blurSigmaX: 30.0,
blurSigmaY: 30.0,
scaleDownFactor: 10.0,
opacity: 0.85,
),
// Your content goes here
Center(
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(10),
),
child: const Text(
'Mica Background Effect',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
],
),
),
);
}
}animationDuration: The duration of the animation when transitioning between wallpapers (default: 1 second)blurSigmaX: The blur intensity in the x-direction (default: 30.0)blurSigmaY: The blur intensity in the y-direction (default: 30.0)scaleDownFactor: The factor by which the image is scaled down before applying blur (default: 10.0)opacity: The opacity of the overlay color (default: 0.85)
The plugin automatically requests the necessary permissions:
- Android: Storage permission (
READ_EXTERNAL_STORAGE) - iOS: Photos permission
- The plugin retrieves the device's current wallpaper using the
device_wallpaper_flutterpackage - It processes the image by scaling it down, applying a blur effect, and then scaling it back up
- The processed image is cached to improve performance
- A hash of the wallpaper is stored to detect when the wallpaper changes
- When the wallpaper changes, the plugin automatically updates the background with a smooth animation
- Large images are automatically downsampled to reduce processing time and memory usage
- Images are cached to avoid reprocessing the same wallpaper multiple times
- Weak references are used to manage image resources efficiently
- Animations are optimized to avoid jank
- The plugin requires access to the device's wallpaper, which may not be available in some restricted environments
- Performance may vary depending on the size and quality of the wallpaper image
- The mica effect may look different depending on the device's screen resolution and brightness
MIT