handleSaveButtonPressed method

Future<void> handleSaveButtonPressed(
  1. BuildContext context
)

Implementation

Future<void> handleSaveButtonPressed(BuildContext context) async {
  try {
    final ui.Image data = await signatureGlobalKey.currentState!.toImage(pixelRatio: pixelRatio);
    final ByteData? bytes = await data.toByteData(format: ui.ImageByteFormat.png);
    if (bytes == null) {
      onError?.call("Failed to convert signature to bytes.");
      return;
    }
    final Uint8List byte = bytes.buffer.asUint8List();
    final File file = await UFile.writeToFile(byte);
    onSave(FileData(path: file.path, bytes: byte, extension: "png"));
  } catch (e) {
    onError?.call("Error saving signature: $e");
    if (context.mounted) {
      UNavigator.snackbar(message: "Error saving signature");
    }
  }
}