useAsImageFromRepaintBoundary method

  1. @override
Future<WallpaperResult> useAsImageFromRepaintBoundary(
  1. GlobalKey<State<StatefulWidget>> boundaryKey, {
  2. double pixelRatio = 2.5,
})
override

Shares / uses an image captured from a RepaintBoundary.

Implementation

@override
Future<WallpaperResult> useAsImageFromRepaintBoundary(
  GlobalKey boundaryKey, {
  double pixelRatio = 2.5,
}) async {
  try {
    final bytes = await _captureWidget(boundaryKey, pixelRatio);
    if (bytes == null) {
      return WallpaperResult.failure(
        WallpaperError.invalidImage,
        message: 'Could not capture the RepaintBoundary widget.',
      );
    }
    return await _useAsImageBytes(bytes);
  } catch (e) {
    return WallpaperResult.failure(
      WallpaperError.platformError,
      message: 'Failed to use image: $e',
    );
  }
}