A flutter package which contains a collection of some functions to set wallpaper on your Android device asynchronously. With this plugin you can also set video live wallpapers (.mp4) natively.
Example in another app | Example app screenshot |
The package allows you to set wallpaper on your Android device asynchronously, in the following ways.
- Set wallpaper from a file path
- Set wallpaper from a URL
- Set wallpaper from a video file (file path)
- Can select locations (HOME, LOCK, BOTH)
Add this to your package's pubspec.yaml
file:
dependencies:
async_wallpaper: ^1.0.0
You can install packages from the command line:
with pub
:
$ pub get
with Flutter
:
$ flutter pub get
Now in your Dart
code, you can use:
import 'package:async_wallpaper/async_wallpaper.dart';
AsyncWallpaper
is a Class that exposes some methods, variables which you can call to set wallpapers.
When you want to set wallpaper simply use it like:
await AsyncWallpaper.setWallpaperFromFile(
file.path, AsyncWallpaper.HOME_SCREEN);
It needs two positional arguments -
filePath
– the path of the file to set as wallpaperwallpaperLocation
– the location where you want to set the wallpaper
AsyncWallpaper has three locations predefined -
HOME_SCREEN
– set wallpaper on home screenLOCK_SCREEN
– set wallpaper on lock screenBOTH_SCREENS
– set wallpaper on both home and lock screen
Below is the detailed usage of the package, including all functions defined.
await AsyncWallpaper.platformVersion ?? 'Unknown platform version';
It returns the platform version of the device. Useful for all the Android 11, 12 permission related stuff.
Setting wallpaper from a file path, on home screen.
String result;
var file = await DefaultCacheManager().getSingleFile(url);
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaperFromFile(
file.path, AsyncWallpaper.HOME_SCREEN);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Setting wallpaper from a file path, on lock screen.
String result;
var file = await DefaultCacheManager().getSingleFile(url);
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaperFromFile(
file.path, AsyncWallpaper.LOCK_SCREEN);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Setting wallpaper from a file path, on both screens.
String result;
var file = await DefaultCacheManager().getSingleFile(url);
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaperFromFile(
file.path, AsyncWallpaper.BOTH_SCREENS);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Note - You can use the
flutter_cache_manager
plugin to download the file from the internet, and get the file path.
Setting wallpaper from a url, on home screen.
String result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaper(
url, AsyncWallpaper.HOME_SCREEN);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Setting wallpaper from a url, on lock screen.
String result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaper(
url, AsyncWallpaper.LOCK_SCREEN);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Setting wallpaper from a url, on both screens.
String result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setWallpaper(
url, AsyncWallpaper.BOTH_SCREENS);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Setting live wallpaper requires .mp4
file. Also currently local files are only supported, so download it before calling this function. The method call redirect to native Android live wallpaper setting intent, so no locations are currently supported.
String result;
var file = await DefaultCacheManager().getSingleFile(liveUrl);
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await AsyncWallpaper.setLiveWallpaper(
file.path);
} on PlatformException {
result = 'Failed to get wallpaper.';
}
Note - You can find more detailed examples in the
example
directory.
If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on GitHub and I'll look into it. Pull request are also welcome.
See Contributing.md.