prepareNextStamp method

Future<void> prepareNextStamp({
  1. String? imagePath,
  2. CPDFStandardStamp? standardStamp,
  3. CPDFTextStamp? textStamp,
})

Pre-configure the next stamp annotation to be inserted when the user taps the page.

Usage: Call this after entering stamp creation mode to specify which kind of stamp (image / standard / text) will be inserted on the next tap.

Constraints: Exactly one of `imagePath`, `standardStamp`, or `textStamp` must be provided. Supplying none or more than one throws an `ArgumentError`.

Parameters: imagePath Path to an image stamp. Android: file path or drawable resource name. iOS: file path or bundled image name. standardStamp Built-in standard stamp enum value (e.g. `CPDFStandardStamp.approved`). textStamp A `CPDFTextStamp` instance defining custom text, colors, size, etc.

Returns: A `Future

Exceptions: `ArgumentError`: Thrown if the "exactly one parameter" rule is violated. Message is in English.

Example:

await controller.prepareNextStamp(imagePath: '/path/to/stamp.png');
await controller.prepareNextStamp(standardStamp: CPDFStandardStamp.approved);
await controller.prepareNextStamp(
  textStamp: CPDFTextStamp(text: 'CONFIDENTIAL', textColor: Colors.red),
);

Implementation

Future<void> prepareNextStamp({
  String? imagePath,
  CPDFStandardStamp? standardStamp,
  CPDFTextStamp? textStamp,
}) async {
  final count =
      [imagePath, standardStamp, textStamp].where((e) => e != null).length;
  if (count != 1) {
    throw ArgumentError(
        'Exactly one argument must be provided: imagePath, standardStamp, or textStamp');
  }
  final Map<String, dynamic> payload = {};
  if (imagePath != null) {
    payload
      ..['type'] = 'image'
      ..['imagePath'] = imagePath;
  } else if (standardStamp != null) {
    payload
      ..['type'] = 'standard'
      ..['standardStamp'] = standardStamp.name;
  } else {
    payload['type'] = 'text';
    payload.addAll(textStamp!.toJson());
  }
  await _channel.invokeMethod('prepare_next_stamp', payload);
}