flutter_camera_ml_vision 2.2.2

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.

Exposed functionality from CameraController #

We expose some functionality from the CameraController class here a a list of these :

  • value
  • prepareForVideoRecording
  • startVideoRecording
  • stopVideoRecording
  • takePicture

Getting Started #

See the example directory for a complete sample app.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Technical Support #

For any technical support, don't hesitate to contact us. Find more information in our website

For now, all the issues with the label support mean that they come out of the scope of the following project. So you can contact us as a support.

[2.2.2] - 02/09/2019

  • fix black screen on some Android device in profile/release mode

[2.2.1] - 19/06/2019

  • fix bug when specifying resolution

[2.2.0] - 16/06/2019

  • disable audio (#43)
  • let user define camera resolution (#45)

[2.1.0] - 16/05/2019

expose more function from camera controller

  • prepareForVideoRecording
  • startVideoRecording
  • stopVideoRecording
  • takePicture

[2.0.1] - 5/05/2019

  • fix a crash when poping a route with the camera preview

[2.0.0] - 2/05/2019

  • We now forward the result from firebase_ml_vision for onResult

[1.5.0] - 24/04/2019

  • fix installation problems
  • Expose camera value

[1.4.0] - 24/04/2019

  • add cameraLensDirection parameter (this default to back)

[1.3.0] - 17/04/2019

  • add overlayBuilder parameter

[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: ^2.2.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub 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';
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 Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/flutter_camera_ml_vision.dart. (-0.50 points)

Analysis of lib/flutter_camera_ml_vision.dart reported 1 hint:

line 92 col 7: Await only futures.

Format lib/utils.dart.

Run flutter format to format lib/utils.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (firebase_ml_vision).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
camera ^0.5.4+1 0.5.4+2
device_info ^0.4.0+2 0.4.0+2
firebase_ml_vision ^0.8.0+3 0.8.0+3 0.9.2+1
flutter 0.0.0
path_provider ^1.2.0 1.3.0
pedantic ^1.7.0 1.8.0+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
platform 2.2.1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies