run method Null safety

  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 {
  final googleVision = await GoogleVision.withJwt(
      globalResults!['credential-file'],
      'https://www.googleapis.com/auth/cloud-vision');

  final painter = Painter.fromFilePath(argResults!['image-file']);

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

  final requests = AnnotationRequests(requests: [
    AnnotationRequest(
      image: Image(painter: painter),
      features: [Feature(type: 'CROP_HINTS')],
      imageContext: aspectRatios != null
          ? ImageContext(
              cropHintsParams: CropHintsParams(aspectRatios: aspectRatios),
            )
          : null,
    )
  ]);

  final annotatedResponses = await googleVision.annotate(requests: requests);

  print(annotatedResponses.responses);
}