google_vision_flutter 2.0.0+2 google_vision_flutter: ^2.0.0+2 copied to clipboard
Add Google Visions image labeling, face, logo, and landmark detection into your Flutter applications.
Google Vision Images Flutter Widget #
Native Dart package that integrates Google Vision features, including image labeling, face, logo, and landmark detection into Flutter applications.
Please feel free to submit PRs for any additional helper methods, or report an issue for a missing helper method and I'll add it if I have time available.
Table of Contents #
Recent Changes #
New for v2.0.0 #
- Even though this package worked when used with the
web
platform the pub.dev analyzer would not show it asweb
platform compatible due to the use of theuniversal_io
package which has a dependency ondart:io
. This version has removed theuniversal_io
dependency from the core package, so some related method signatures have been removed. - The deprecated methods from in v1.3.x have been removed in this version.
- Logging functionality has been added to the package
final googleVision = await GoogleVision(LogLevel.all).withJwtFile('service_credentials.json');
New for v1.4.0 #
- A breaking change from the previous version is that the
GoogleVision
class now follows the Singleton design pattern. Now the object is instantiated as follows:
// Old method from v1.3.x and earlier
// final googleVision = await GoogleVision.withJwtFile('service_credentials.json');
// New
final googleVision = await GoogleVision().withJwtFile('service_credentials.json');
Getting Started #
pubspec.yaml #
To use this package, add the dependency to your pubspec.yaml
file:
dependencies:
...
google_vision_flutter: ^2.0.0
Obtaining Authorization Credentials #
Authenticating to the Cloud Vision API requires an API key or a JSON file with the JWT token information. The JWT token can obtained by creating a service account in the Google API console.
Usage of the GoogleVisionBuilder Widget #
See the example app for the full code.
import 'package:flutter/material.dart';
import 'package:google_vision_flutter/google_vision_flutter.dart';
import 'example_base.dart';
class LabelDetectionPage extends ExampleBase {
// final googleVision =
// GoogleVision().withAsset('assets/service_credentials.json');
static const assetName = 'assets/setagaya_small.jpg';
final _processImage = Image.asset(
assetName,
fit: BoxFit.fitWidth,
);
LabelDetectionPage({
super.key,
required super.googleVision,
required super.title,
});
@override
Widget build(BuildContext context) => SafeArea(
child: Scaffold(
appBar: getAppBar(context),
body: simpleColumn(
assetName: assetName,
sampleImage: _processImage,
result: GoogleVisionImageBuilder.labelDetection(
googleVision: googleVision,
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()),
),
),
),
),
);
}
/// See the example project for all the necessary code.
ShoutOut #
- To Andrii Syrokomskyi for creating flutter_image_converter, I've borrowed some of the code included in the
flutter_image_converter
in this package. This package originally had a dependency onflutter_image_converter
, but that had to be removed to achieveweb
platform support.
Contributing #
Any help from the open-source community is always welcome and needed:
- Found an issue?
- Please fill a bug report with details.
- Need a feature?
- Open a feature request with use cases.
- Are you using and liking the project?
- Promote the project: create an article or post about it
- Make a donation
- Do you have a project that uses this package
- let's cross promote, let me know and I'll add a link to your project
- Are you a developer?
- Fix a bug and send a pull request.
- Implement a new feature.
- Improve the Unit Tests.
- Have you already helped in any way?
- Many thanks from me, the contributors and everybody that uses this project!
If you donate 1 hour of your time, you can contribute a lot, because others will do the same, just be part and start with your 1 hour.