google_vision_flutter 1.4.0 copy "google_vision_flutter: ^1.4.0" to clipboard
google_vision_flutter: ^1.4.0 copied to clipboard

Add Google Visions image labeling, face, logo, and landmark detection into your Flutter applications.

Google Vision Images Flutter Widget #

pub package License: MIT

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 #

Build Status github last commit github build github issues

Buy me a coffee

Recent Changes #

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: ^1.4.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';

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

  final String title;

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

class _MyHomePageState extends State<LabelDetection> {
  final imageAsset = 'assets/setagaya_small.jpg';

  final _processImage = Image.asset(
    imageAsset,
    fit: BoxFit.fitWidth,
  );

  @override
  Widget build(BuildContext context) => SafeArea(
        child: Scaffold(
          appBar: AppBar(
            leading: IconButton(
              icon: const Icon(Icons.arrow_back, color: Colors.black),
              onPressed: () => Navigator.of(context).pop(),
            ),
            title: Text(widget.title),
          ),
          body: SingleChildScrollView(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  const Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Text(imageAsset),
                  ),
                  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()),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      );
}

/// See the example project for all the necessary code.

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.

10
likes
140
pub points
71%
popularity

Publisher

verified publishermuayid.com

Add Google Visions image labeling, face, logo, and landmark detection into your Flutter applications.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

dio, flutter, flutter_image_converter, google_vision, universal_io

More

Packages that depend on google_vision_flutter