toImage method
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();
- Create a SfSignaturePad and assign the global key to it.
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:
- renderToContext2D, renders the signature to a HTML canvas.
Implementation
Future<ui.Image> toImage({double pixelRatio = 1.0}) {
final RenderObject? signatureRenderBox = context.findRenderObject();
// ignore: avoid_as
return (signatureRenderBox! as RenderSignaturePad)
.toImage(pixelRatio: pixelRatio);
}