搜索插件、代码仓与 APP 分类

插件详情v1.2.0

wallpaper

该插件的用途是从 URL 设置壁纸。仅支持 Android。内部使用 WallpaperManager 来设置壁纸。

Android
近 30 天下载
575
喜欢数
52
Pub 分数
160

安装插件

flutter pub add wallpaper

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该壁纸包允许使用 URL 在 Android 设备上设置壁纸。它在内部利用 Android WallpaperManager API,将来自网络 URL 的图像应用为壁纸。专为 Android 设计,不支持 iOS。该插件易于集成,适用于允许用户通过动态或用户选择的图片自定义设备主屏幕的应用程序。它需要适当的权限,并可在针对 Android 的 Flutter 应用中无缝工作。

适合场景

  • 从URL设置动态壁纸
  • 在应用中自定义设备主页屏幕
  • 启用用户壁纸选择
  • 自动化壁纸更新
  • 集成基于图像的主题

主要特点

  • 从 URL 设置壁纸
  • 使用原生 WallpaperManager API
  • 仅限 Android 支持
  • 与 Flutter 的简单集成
  • 支持远程图像源

适合对象

  • Android应用开发者
  • 壁纸自定义功能
  • 具有动态主题选项的应用程序
  • 基于图像的用户体验
  • 需要设备级更改的移动应用

使用建议

  • 仅适用于 Android
  • 需要运行时权限
  • 仅限 Android 的 WallpaperManager
  • 在处理大尺寸或不支持的图像格式时可能会失败
  • 不支持 iOS 平台

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Wallpaper

A Flutter plugin that allows you to download an image from a URL and set it as wallpaper on Android.

The plugin supports setting wallpapers for:

  • Home screen
  • Lock screen
  • Both screens
  • System wallpaper

Features

  • Download image from URL
  • Track download progress
  • Set wallpaper for home screen
  • Set wallpaper for lock screen
  • Set wallpaper for both screens
  • Set system wallpaper
  • Resize images before setting wallpaper
  • Use modern opt-in fit modes for source-based wallpapers
  • Read the platform-recommended wallpaper size
  • Open the Android system wallpaper chooser

Installation

Add the plugin to your pubspec.yaml:

dependencies:
  wallpaper: ^1.2.0

Then run:

flutter pub get

Android Configuration

The plugin manifest already declares the permissions it needs for downloading network images and setting wallpapers:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SET_WALLPAPER"/>

Downloaded images are stored in app-private cache, files, or external files directories depending on DownloadLocation. Apps using the default workflow do not need READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE, and they do not need to add their own file_paths.xml.


Usage

Import the plugin:

import 'package:wallpaper/wallpaper.dart';

Recommended Wallpaper Size

Use the recommended size when choosing, generating, cropping, or downloading an image for the current Android launcher:

final size = await Wallpaper.recommendedWallpaperSize();
print('${size.width} x ${size.height}');

Open Wallpaper Chooser

Open Android's built-in wallpaper chooser without passing a specific image:

await Wallpaper.openWallpaperChooser();

Download Image

final stream = Wallpaper.imageDownloadProgress(
  imageUrl,
  location: DownloadLocation.applicationDirectory,
);

stream.listen((progress) {
  print(progress);
});

Typed Download Operation

Use download when you need typed progress, headers, timeouts, cache reuse, or cancellation:

final operation = Wallpaper.download(
  imageUrl,
  options: const WallpaperDownloadOptions(
    imageName: 'daily_wallpaper',
    headers: {'Authorization': 'Bearer token'},
    connectTimeout: Duration(seconds: 15),
    receiveTimeout: Duration(seconds: 30),
    cachePolicy: WallpaperCachePolicy.reuse,
  ),
);

operation.progress.listen((progress) {
  print(progress.percentage);
});

final file = await operation.completed;

await Wallpaper.homeScreen(
  imageName: file.imageName,
  fileExtension: file.fileExtension,
  location: file.location,
);

Cancel an active operation:

await operation.cancel();

Clear plugin-managed temporary downloads created by the typed download API:

await Wallpaper.clearCache();

Set Home Screen Wallpaper

await Wallpaper.homeScreen(
  width: width,
  height: height,
  options: RequestSizeOptions.resizeFit,
  location: DownloadLocation.applicationDirectory,
);

Set Lock Screen Wallpaper

await Wallpaper.lockScreen(
  location: DownloadLocation.applicationDirectory,
);

Set Both Wallpapers

await Wallpaper.bothScreen(
  location: DownloadLocation.applicationDirectory,
);

Set System Wallpaper

await Wallpaper.systemScreen(
  location: DownloadLocation.applicationDirectory,
);

Set Wallpaper From a Local File

await Wallpaper.setFromFile(
  file.path,
  target: WallpaperTarget.home,
  options: RequestSizeOptions.resizeFit,
  fit: WallpaperFit.cover,
  alignment: WallpaperAlignment.topCenter,
);

alignment is optional and defaults to center. It applies to WallpaperFit.cover cropping and WallpaperFit.center placement.


Set Wallpaper From Bytes

await Wallpaper.setFromBytes(
  imageBytes,
  target: WallpaperTarget.both,
  fileExtension: ImageFormat.png,
);

Set Wallpaper From an Asset

await Wallpaper.setFromAsset(
  'assets/wallpaper.jpg',
  target: WallpaperTarget.lock,
);

For assets bundled by another package:

await Wallpaper.setFromAsset(
  'assets/wallpaper.jpg',
  package: 'wallpaper_assets',
);

Unified Source API

Use setWallpaperFromSource when you prefer a typed result instead of catching PlatformException from the legacy methods:

final result = await Wallpaper.setWallpaperFromSource(
  source: WallpaperSource.file(file.path),
  options: const WallpaperOptions(
    target: WallpaperTarget.home,
    fit: WallpaperFit.cover,
    alignment: WallpaperAlignment.topCenter,
  ),
);

switch (result) {
  case WallpaperSuccess(:final message):
    print(message);
  case WallpaperFailure(:final exception):
    print('${exception.code}: ${exception.message}');
}

Example

final stream = Wallpaper.imageDownloadProgress(imageUrl);

stream.listen((progress) {
  print("Downloading: $progress");
}, onDone: () async {

  await Wallpaper.homeScreen(
    width: 1080,
    height: 1920,
    options: RequestSizeOptions.resizeFit,
  );

});

Supported Platform

Platform Supported
Android ✅
iOS ❌

Notes

  • Internet connection is required to download images.
  • Lock screen wallpaper requires Android 7.0+ (API 24).
  • Behavior may vary depending on device manufacturer.
  • Starting multiple downloads with the same imageName writes to the same file. Use unique names for concurrent downloads.

License

MIT License

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

暂无相关数据。