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

插件详情v1.0.10

wallpaper_manager

一个用于在 Android 设备上更改主屏幕、锁屏(或两者)壁纸的 Flutter 插件。

近 30 天下载
83
喜欢数
103
Pub 分数
40

安装插件

flutter pub add wallpaper_manager

插件介绍

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

Wallpaper Manager 是一个 Flutter 插件,可让开发者在 Android 设备上通过编程方式设置主屏幕、锁屏或两者同时的壁纸。它提供了一个简单的接口,允许直接从 Flutter 应用中将图片应用为壁纸,从而提升照片或个性化应用的用户体验。该插件利用原生 Android API,目前仅支持 Android,没有 iOS 实现。它需要适当的权限,并且在专注于个性化、图像画廊或数字艺术展示的应用中集成效果最佳。

适合场景

  • 从应用内容设置动态壁纸
  • 创建具有壁纸功能的相册应用
  • 在生活方式应用中启用用户自定义
  • 在数字艺术平台中集成壁纸更改

主要特点

  • 设置主屏幕壁纸
  • 设置锁屏壁纸
  • 同时支持两个屏幕
  • 与 Flutter 的简单 API 集成
  • 使用原生 Android 壁纸 API

适合对象

  • 仅限 Android 的应用需要更改壁纸
  • 照片和艺术分享应用
  • 用户个性化工具
  • 具有动态背景主题的应用程序

使用建议

  • 仅适用于安卓设备
  • 需要运行时权限请求
  • 受限于 Android 的壁纸系统
  • 不支持 iOS
  • 可能需要处理图像分辨率和格式

原始 README

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

wallpaper_manager

Wallpaper Manager

A Flutter plugin for changing the Home Screen, Lock Screen (or both) Wallpaper(s) on Android devices.

Pub

Usage

Installation

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  wallpaper_manager: "^1.0.10"

In your library add the following import:

import 'package:wallpaper_manager/wallpaper_manager.dart';
Example
Basic Usage

Since this is not a Widget, you have to create WallpaperManager constructors from inside an async function, which is a Future that returns a String output specifying success/failure.

String path = "/path/to/file/on/disk";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
final String result = await WallpaperManager.setWallpaperFromFile(path, location);
Basic Usage with error handling

You might want to wrap it in a try/catch since platform messages (plug-ins like these) may fail

String path = "/path/to/file/on/disk";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
try {
  result = await WallpaperManager.setWallpaperFromFile(path, location);
} on PlatformException {
  result = 'Failed to get wallpaper.';
}
Loading from a URL (with CacheManager, the image is saved to app files as well)

If you're loading a Wallpaper from a URL, you should save it to the disk first, then use the path of the saved image file. Add flutter_cache_manager or any other dependency you'd like:

dependencies:
  ...
  flutter_cache_manager: "^1.1.3"

And in dart code

String url = "";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
var file = await DefaultCacheManager().getSingleFile(url);
final String result = await WallpaperManager.setWallpaperFromFile(file.path, location);
Loading from a Flutter asset

If you're loading a Wallpaper from an asset, you need to make sure it is indexed in the pubspec.yaml file first

dependencies:
  ...
  flutter:
    ...
    assets:
    - assets/tmp1.jpeg

And in dart code

String assetPath = "assets/tmp1.jpg";
int location = WallpaperManager.HOME_SCREEN; // or location = WallpaperManager.LOCK_SCREEN;
String result;
final String result = await WallpaperManager.setWallpaperFromAsset(assetPath, location);

Getting started

With Wallpaper Manager

See the example directory for a complete sample app using Wallpaper Manager.

With Flutter

For help getting started with Flutter, view the online documentation.

Notes

  • iOS does not support changing Wallpapers from third-party apps (Source)
  • Xiaomi/MIUI does not support changing Lock Screen Wallpapers directly from the Android API (Source). You might want to look at creating a Lock Screen Launcher app instead.

Known Issues

Todos

  • [ ] Write tests
  • [x] Add rect values for optionally cropping the image
  • [ ] Add variable for re-using Wallpaper from phone's settings
  • [ ] Write more tests

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

源码仓库

使用此插件的项目