annotate method Null safety

Future<AnnotatedResponses> annotate(
  1. [String? features]
)

Helper methods used by most of the cli commands.

Implementation

Future<AnnotatedResponses> annotate([String? features]) async {
  final googleVision = await GoogleVision.withJwt(
      globalResults!['credential-file'],
      'https://www.googleapis.com/auth/cloud-vision');

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

  final featureList = (features ?? (argResults!['features'] as String))
      .split(',')
      .map((element) => Feature(
          maxResults: int.parse(argResults!['max-results']), type: element))
      .toList();

  final requests = AnnotationRequests(
      requests: [AnnotationRequest(painter: painter, features: featureList)]);

  return await googleVision.annotate(requests: requests);
}