setWallpaper method

  1. @override
Future<bool> setWallpaper(
  1. GlobalKey<State<StatefulWidget>> boundaryKey,
  2. String target, {
  3. double pixelRatio = 2.5,
})
override

Implementation

@override
Future<bool> setWallpaper(
  GlobalKey boundaryKey,
  String target, {
  double pixelRatio = 2.5,
}) async {
  try {
    final bytes = await _captureWidget(boundaryKey, pixelRatio);
    if (bytes == null) return false;

    final filePath = await _saveTempFile(bytes, 'wallpaper');

    final bool success =
        await methodChannel.invokeMethod('setWallpaper', {
          'path': filePath,
          'target': target,
        }) ??
        false;

    // Cleanup
    await File(filePath).delete().catchError((_) => File(filePath));

    return success;
  } on PlatformException catch (e) {
    debugPrint('setWallpaper error: ${e.message}');
    return false;
  }
}