flutter_camera_ml_vision 1.2.0

  • README.md
  • Example
  • Installing
  • Versions
  • new57

Flutter Camera Ml Vision #

pub package

A Flutter package for iOS and Android to show a preview of the camera and detect things with Firebase ML Vision.

Installation #

First, add `flutter_camera_ml_vision as a dependency.

    sdk: flutter
  flutter_camera_ml_vision: ^1.0.0

Configure Firebase #

You must also configure Firebase for each platform project: Android and iOS (see the example folder or https://codelabs.developers.google.com/codelabs/flutter-firebase/#4 for step by step details).

iOS #

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Microphone Usage Description and a usage description. Or in text format add the key:
<string>Can I use the camera please?</string>
<string>Can I use the mic please?</string>

If you're using one of the on-device APIs, include the corresponding ML Kit library model in your Podfile. Then run pod update in a terminal within the same directory as your Podfile.

pod 'Firebase/MLVisionBarcodeModel'
pod 'Firebase/MLVisionFaceModel'
pod 'Firebase/MLVisionLabelModel'
pod 'Firebase/MLVisionTextModel'

Android #

Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

ps: This is due to the dependency on the camera plugin.

If you're using the on-device LabelDetector, include the latest matching ML Kit: Image Labeling dependency in your app-level build.gradle file.

android {
    dependencies {
        // ...

        api 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'

If you receive compilation errors, try an earlier version of ML Kit: Image Labeling.

Optional but recommended: If you use the on-device API, configure your app to automatically download the ML model to the device after your app is installed from the Play Store. To do so, add the following declaration to your app's AndroidManifest.xml file:

<application ...>
    android:value="ocr" />
  <!-- To use multiple models: android:value="ocr,label,barcode,face" -->

Usage #

1. Example with Barcode #

  detector: FirebaseVision.instance.barcodeDetector().detectInImage,
  onResult: (List<Barcode> barcodes) {
    if (!mounted || resultSent) {
    resultSent = true;

CameraMlVision is a widget that show the preview of the camera. It take a detector as parameter here we pass the detectInImage method of the BarcodeDetector object. The detector parameter can take all the different FirebaseVision Detector. Here is a list :


Then when something is detected the onResult callback is called with the data in the parameter of the function.

Getting Started #

See the example directory for a complete sample app.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

[1.2.0] - 12/04/2019

  • fix crash above android api 21.
  • fix pause when a new route is pushed.

[1.1.0] - 11/04/2019

  • Allow usage under android api 21.
  • Add error type on error builder.

[1.0.0] - 10/04/2019

  • Initial release.


import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:flutter/material.dart';
import 'package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      home: MyHomePage(title: 'Flutter Demo Home Page'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  List<String> data = [];

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
            child: Text('Scan product'),
            onPressed: () async {
              final barcode = await Navigator.of(context).push<Barcode>(
                  builder: (c) {
                    return ScanPage();
              if (barcode == null) {

              setState(() {
            child: ListView(
              children: data.map((d) => Text(d)).toList(),
      ), // This trailing comma makes auto-formatting nicer for build methods.

class ScanPage extends StatefulWidget {
  _ScanPageState createState() => _ScanPageState();

class _ScanPageState extends State<ScanPage> {
  bool resultSent = false;
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          width: MediaQuery.of(context).size.width,
          child: CameraMlVision<List<Barcode>>(
            detector: FirebaseVision.instance.barcodeDetector().detectInImage,
            onResult: (List<Barcode> barcodes) {
              if (!mounted || resultSent) {
              resultSent = true;

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_camera_ml_vision: ^1.2.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart';
Version Uploaded Documentation Archive
1.2.0 Apr 12, 2019 Go to the documentation of flutter_camera_ml_vision 1.2.0 Download flutter_camera_ml_vision 1.2.0 archive
1.1.0 Apr 11, 2019 Go to the documentation of flutter_camera_ml_vision 1.1.0 Download flutter_camera_ml_vision 1.1.0 archive
1.0.0+1 Apr 10, 2019 Go to the documentation of flutter_camera_ml_vision 1.0.0+1 Download flutter_camera_ml_vision 1.0.0+1 archive
1.0.0 Apr 10, 2019 Go to the documentation of flutter_camera_ml_vision 1.0.0 Download flutter_camera_ml_vision 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Prefer published dependencies. (-100 points)

The source code in a git repository is mutable and could disappear.

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: camera.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
camera 0.4.4
device_info ^0.4.0+1 0.4.0+1
firebase_ml_vision ^0.7.0 0.7.0
flutter 0.0.0
path_provider ^0.5.0+1 0.5.0+1
pedantic ^1.4.0 1.5.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies