wallpaper
이 플러그인의 목적은 URL에서 벽지로 설정하는 것입니다. Android에서만 지원됩니다. 내부적으로 WallpaperManager를 사용하여 벽지를 설정합니다.
pratiktimer/setWallpaperplugin open-source repository details.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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:
Add the plugin to your pubspec.yaml:
dependencies:
wallpaper: ^1.2.0
Then run:
flutter pub get
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.
Import the plugin:
import 'package:wallpaper/wallpaper.dart';
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 Android's built-in wallpaper chooser without passing a specific image:
await Wallpaper.openWallpaperChooser();
final stream = Wallpaper.imageDownloadProgress(
imageUrl,
location: DownloadLocation.applicationDirectory,
);
stream.listen((progress) {
print(progress);
});
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();
await Wallpaper.homeScreen(
width: width,
height: height,
options: RequestSizeOptions.resizeFit,
location: DownloadLocation.applicationDirectory,
);
await Wallpaper.lockScreen(
location: DownloadLocation.applicationDirectory,
);
await Wallpaper.bothScreen(
location: DownloadLocation.applicationDirectory,
);
await Wallpaper.systemScreen(
location: DownloadLocation.applicationDirectory,
);
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.
await Wallpaper.setFromBytes(
imageBytes,
target: WallpaperTarget.both,
fileExtension: ImageFormat.png,
);
await Wallpaper.setFromAsset(
'assets/wallpaper.jpg',
target: WallpaperTarget.lock,
);
For assets bundled by another package:
await Wallpaper.setFromAsset(
'assets/wallpaper.jpg',
package: 'wallpaper_assets',
);
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}');
}
final stream = Wallpaper.imageDownloadProgress(imageUrl);
stream.listen((progress) {
print("Downloading: $progress");
}, onDone: () async {
await Wallpaper.homeScreen(
width: 1080,
height: 1920,
options: RequestSizeOptions.resizeFit,
);
});
| Platform | Supported |
|---|---|
| Android | ✅ |
| iOS | ❌ |
imageName writes to the same file.
Use unique names for concurrent downloads.MIT License
의존성 목록 8 개
{"sdk":"flutter"}{"sdk":"flutter"}^1.0.0^2.0.2^5.3.0^2.0.15{"sdk":"flutter"}^5.0.0사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗