24 lines
703 B
Dart
24 lines
703 B
Dart
// Author: fengshengxiong
|
|
// Date: 2024/5/17
|
|
// Description: 设置壁纸插件
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
class SetWallpaper {
|
|
static const MethodChannel _channel = MethodChannel('set_wallpaper');
|
|
|
|
static Future<String> setWallpaper(String path, int wallpaperType) async {
|
|
try {
|
|
final String result = await _channel.invokeMethod('setWallpaper', {
|
|
"path": path,
|
|
"wallpaperType": wallpaperType // 0 for home screen, 1 for lock screen, 2 for both
|
|
});
|
|
print(result);
|
|
return result;
|
|
} on PlatformException catch (e) {
|
|
print('Failed to set wallpaper: ${e.message}.');
|
|
return 'Failed to set wallpaper: ${e.message}.';
|
|
}
|
|
}
|
|
}
|