imageFromWidget function

Future<ImageReference> imageFromWidget(
  1. FlutterPowerPoint pres,
  2. Widget builder(
    1. Size size
    ), {
  3. Duration delay = const Duration(seconds: 1),
  4. double? pixelRatio,
  5. BuildContext? context,
  6. Size? targetSize,
})

Implementation

Future<ImageReference> imageFromWidget(
  FlutterPowerPoint pres,
  Widget Function(Size size) builder, {
  Duration delay = const Duration(seconds: 1),
  double? pixelRatio,
  BuildContext? context,
  Size? targetSize,
}) async {
  final ctx = pres.context as FlutterPresentationContext;
  final size = targetSize ??
      Size(
        Util.ptToPixle(pres.layout.width),
        Util.ptToPixle(pres.layout.height),
      );
  final bytes = await ctx.screenshotController.captureFromWidget(
    builder(size),
    delay: delay,
    pixelRatio: pixelRatio,
    context: context,
    targetSize: size,
  );
  final image = ImageReference.fromBytes(
    bytes,
    name: 'widget',
    description: 'image created from a widget',
  );
  return image;
}