Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mica Background Plugin

A Flutter plugin that creates a beautiful mica-like translucent effect using the device's wallpaper, similar to Windows 11's Mica material.

Features

  • 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

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  mica_background: ^0.0.1

Then run:

flutter pub get

Usage

Import 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,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Parameters

  • 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)

Permissions

The plugin automatically requests the necessary permissions:

  • Android: Storage permission (READ_EXTERNAL_STORAGE)
  • iOS: Photos permission

How It Works

  1. The plugin retrieves the device's current wallpaper using the device_wallpaper_flutter package
  2. It processes the image by scaling it down, applying a blur effect, and then scaling it back up
  3. The processed image is cached to improve performance
  4. A hash of the wallpaper is stored to detect when the wallpaper changes
  5. When the wallpaper changes, the plugin automatically updates the background with a smooth animation

Performance Optimization

  • 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

Limitations

  • 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

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages