run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  try {
    await initializeGoogleVision();

    final aspectRatios = argResults?['aspect-ratios'] == null
        ? null
        : argResults!['aspect-ratios']
            .toString()
            .split(',')
            .map((aspectRatio) => double.parse(aspectRatio))
            .toList();

    final imageContext = aspectRatios != null
        ? ImageContext(
            cropHintsParams: CropHintsParams(aspectRatios: aspectRatios),
          )
        : null;

    if (pages != null) {
      final annotatedResponses = await googleVision.file.cropHints(
        InputConfig.fromBuffer(imageBytes.buffer),
        imageContext: imageContext,
        pages: pages!,
      );

      print(annotatedResponses);
    } else {
      final annotatedResponses = await googleVision.image.cropHints(
        JsonImage.fromBuffer(imageBytes.buffer),
        imageContext: imageContext,
      );

      print(annotatedResponses?.cropHints);
    }
  } on DioException catch (err) {
    throw UsageException('API usage error:', err.usage);
  }
}