toImage method Null safety

Future<Image> toImage(
  1. {double pixelRatio = 1.0}
)

Saves the signature as an image. Returns the ui.Image.

Since this method is defined in the state object of SfSignaturePad, you have to use a global key assigned to the SfSignaturePad instance to call this method.

This snippet shows how to use toImage in SfSignaturePadState.

  • Create a global key.
final GlobalKey<SfSignaturePadState> _signaturePadKey = GlobalKey();
SfSignaturePad(
  key: _signaturePadKey,
 );
  • Call toImage using state object to convert the signature to an image. representation.
 ui.Image image = await _signaturePadKey.currentState!.toImage();

See also:

Implementation

Future<ui.Image> toImage({double pixelRatio = 1.0}) {
  final RenderObject? signatureRenderBox = context.findRenderObject();
  // ignore: avoid_as
  return (signatureRenderBox! as RenderSignaturePad)
      .toImage(pixelRatio: pixelRatio);
}