Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
faithoflifedev committed Aug 28, 2024
1 parent 976b75f commit 8a3e1d2
Show file tree
Hide file tree
Showing 26 changed files with 1,117 additions and 1,418 deletions.
5 changes: 5 additions & 0 deletions packages/google_vision_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.3.0+2

* removed FutureBuilder nesting
* simplified builder signature

## 1.3.0

* added back the google_vision re-export
Expand Down
139 changes: 54 additions & 85 deletions packages/google_vision_flutter/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Google Vision Images Flutter Widget

[![pub package](https://img.shields.io/pub/v/google_vision_flutter.svg)](https://pub.dartlang.org/packages/google_vision_flutter)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Native [Dart](https://dart.dev/) package that integrates Google Vision features, including image labeling, face, logo, and landmark detection into Flutter applications.

[![Build Status](https://github.com/faithoflifedev/google_vision/workflows/Dart/badge.svg)](https://github.com/faithoflifedev/google_vision/actions) [![github last commit](https://shields.io/github/last-commit/faithoflifedev/google_vision)](https://shields.io/github/last-commit/faithoflifedev/google_vision) [![github build](https://img.shields.io/github/actions/workflow/status/faithoflifedev/google_vision_workspace/flutter.yaml?branch=main)](https://shields.io/github/workflow/status/faithoflifedev/google_vision/Dart) [![github issues](https://shields.io/github/issues/faithoflifedev/google_vision)](https://shields.io/github/issues/faithoflifedev/google_vision)

Please feel free to submit PRs for any additional helper methods, or report an [issue](https://github.com/faithoflifedev/google_vision/issues) for a missing helper method and I'll add it if I have time available.

## Table of Contents
- [Getting Started](#getting-started)
- [pubspec.yaml](#pubspecyaml)
- [Obtaining Authorization Credentials](#obtaining-authorization-credentials)
- [Usage of the GoogleVisionBuilder Widget](#usage-of-the-googlevisionbuilder-widget)
- [Contributing](#contributing)

- [Google Vision Images Flutter Widget](#google-vision-images-flutter-widget)
- [Table of Contents](#table-of-contents)
- [Getting Started](#getting-started)
- [pubspec.yaml](#pubspecyaml)
- [Obtaining Authorization Credentials](#obtaining-authorization-credentials)
- [Usage of the GoogleVisionBuilder Widget](#usage-of-the-googlevisionbuilder-widget)
- [Contributing](#contributing)

[![Build Status](https://github.com/faithoflifedev/google_vision/workflows/Dart/badge.svg)](https://github.com/faithoflifedev/google_vision/actions) [![github last commit](https://shields.io/github/last-commit/faithoflifedev/google_vision)](https://shields.io/github/last-commit/faithoflifedev/google_vision) [![github build](https://img.shields.io/github/actions/workflow/status/faithoflifedev/google_vision_workspace/flutter.yaml?branch=main)](https://shields.io/github/workflow/status/faithoflifedev/google_vision/Dart) [![github issues](https://shields.io/github/issues/faithoflifedev/google_vision)](https://shields.io/github/issues/faithoflifedev/google_vision)

[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/guidelines/download-assets-1.svg)](https://www.buymeacoffee.com/faithoflif2)

## Getting Started

Expand All @@ -27,13 +28,13 @@ To use this package, add the dependency to your `pubspec.yaml` file:
```yaml
dependencies:
...
google_vision_flutter: ^1.3.0
google_vision_flutter: ^1.3.0+2
```
### Obtaining Authorization Credentials
[Authenticating to the Cloud Vision API](https://cloud.google.com/vision/product-search/docs/auth) requires a JSON file with the JWT token information, which you can obtain by [creating a service account](https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating_a_service_account) in the API console.
[Authenticating to the Cloud Vision API](https://cloud.google.com/vision/product-search/docs/auth) requires an API key or a JSON file with the JWT token information. The JWT token can obtained by [creating a service account](https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating_a_service_account) in the Google API console.
### Usage of the GoogleVisionBuilder Widget
Expand All @@ -43,18 +44,18 @@ See the [example app](https://github.com/faithoflifedev/google_vision_workspace/
import 'package:flutter/material.dart';
import 'package:google_vision_flutter/google_vision_flutter.dart';

class FaceDetection extends StatefulWidget {
const FaceDetection({super.key, required this.title});
class LabelDetection extends StatefulWidget {
const LabelDetection({super.key, required this.title});

final String title;

@override
State<FaceDetection> createState() => _MyHomePageState();
State<LabelDetection> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<FaceDetection> {
class _MyHomePageState extends State<LabelDetection> {
final _processImage = Image.asset(
'assets/young-man-smiling.jpg',
'assets/setagaya_small.jpg',
fit: BoxFit.fitWidth,
);

Expand All @@ -69,42 +70,46 @@ class _MyHomePageState extends State<FaceDetection> {
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('assets/young-man-smiling.jpg'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _processImage,
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Processed image will appear below:',
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('assets/setagaya_small.jpg'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: GoogleVisionBuilder.faceDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
imageProvider: _processImage.image,
builder: (BuildContext context,
List<FaceAnnotation>? faceAnnotations,
ImageDetail imageDetail) =>
CustomPaint(
foregroundPainter: AnnotationPainter(
faceAnnotations: faceAnnotations,
imageDetail: imageDetail,
),
child: Image(image: _processImage.image),
Padding(
padding: const EdgeInsets.all(8.0),
child: _processImage,
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Process result will appear below:',
),
),
)
],
Padding(
padding: const EdgeInsets.all(8.0),
child: GoogleVisionBuilder.labelDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
imageProvider: _processImage.image,
builder: (
BuildContext context,
List<EntityAnnotation>? entityAnnotations,
) =>
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: entityAnnotations!
.map((entity) => Text(
'${(entity.score! * 100).toStringAsFixed(2)}% - ${entity.description}'))
.toList()),
),
),
)
],
),
),
),
),
Expand All @@ -117,42 +122,6 @@ class _MyHomePageState extends State<FaceDetection> {

<center><img src="https://github.com/faithoflifedev/google_vision_workspace/blob/main/packages/google_vision_flutter/screenshot/face_detection.png?raw=true&amp;v1" width="320"></center>

## Major Changes for v1.1.x

Starting with this version of the package, the `google_vision` package is not re-exported by `google_vision_flutter`, this means that you must import `google_vision` manually in the cases that you need any classes that are part of it's API.

```dart
import 'package:flutter/material.dart';
import 'package:google_vision/google_vision.dart' as gv;
import 'package:google_vision_flutter/google_vision_flutter.dart';
GoogleVisionBuilder.faceDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
imageProvider: _processImage.image,
builder: (BuildContext context,
List<gv.FaceAnnotation>? faceAnnotations,
ImageDetail imageDetail) =>
CustomPaint(
foregroundPainter: AnnotationPainter(
faceAnnotations: faceAnnotations,
imageDetail: imageDetail,
),
child: Image(image: _processImage.image),
),
),
```

In this code snippet the `FaceAnnotation` class is referenced as `gv.FaceAnnotation` since the class is part of the `google_vision` package.

Previous versions of the `google_vision_flutter` package reexported the `google_vision` package as part of the it's library definition. This lead to warnings like:

```text
warning: private API of package:google_Vision is reexported by libraries in other packages:
```

During analysis of the package. The updated package does not generate these warnings.

## Contributing

Any help from the open-source community is always welcome and needed:
Expand Down
5 changes: 3 additions & 2 deletions packages/google_vision_flutter/example/lib/crop_hints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ class _MyHomePageState extends State<CropHints> {
builder: (
BuildContext context,
CropHintsAnnotation? cropHintsAnnotation,
ImageDetail? imageDetail,
) =>
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: cropHintsAnnotation!.cropHints
.map((cropHint) => Text('$cropHint'))
.map((cropHint) => Center(
child: Text('$cropHint'),
))
.toList()),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ class _MyHomePageState extends State<DocumentTextDetection> {
builder: (
BuildContext context,
FullTextAnnotation? fullTextAnnotation,
ImageDetail? imageDetail,
) =>
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: fullTextAnnotation!.pages
.map((page) => Row(
children: [
const Text('Page Language - '),
Text(page.property?.detectedLanguages
?.first.languageCode ??
''),
],
.map((page) => Center(
child: Text(
'Page Language - ${page.property?.detectedLanguages?.first.languageCode ?? ''}',
),
))
.toList()),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,54 @@ class _MyHomePageState extends State<DocumentTextDetectionFile> {
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ElevatedButton(
child: const Text('Show PDF Content'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const ShowPdf(assetName: assetName),
),
)),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Process result will appear below:',
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ElevatedButton(
child: const Text('Show PDF Content'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const ShowPdf(assetName: assetName),
),
)),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Process result will appear below:',
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: GoogleVisionFileBuilder.documentTextDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
inputConfig: InputConfig.fromAsset('assets/allswell.pdf'),
builder: (
BuildContext context,
List<AnnotateFileResponse>? responses,
Future<InputConfig> inputConfig,
) =>
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: responses!
.map((annotateFileResponse) => Row(
children: [
const Text('Total Pages - '),
Text(
'${annotateFileResponse.totalPages}'),
],
))
.toList()),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
assetName,
),
),
)
],
Padding(
padding: const EdgeInsets.all(8.0),
child: GoogleVisionFileBuilder.documentTextDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
inputConfig: InputConfig.fromAsset('assets/allswell.pdf'),
builder: (
BuildContext context,
List<AnnotateFileResponse>? responses,
) =>
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: responses!
.map(
(annotateFileResponse) => Text(
'Total Pages - ${annotateFileResponse.totalPages}'),
)
.toList()),
),
),
)
],
),
),
),
),
Expand Down
Loading

0 comments on commit 8a3e1d2

Please sign in to comment.