diff --git a/android/app/build.gradle b/android/app/build.gradle
index 63663905..ed0f5f0d 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -39,7 +39,7 @@ android {
defaultConfig {
applicationId "io.github.x_wei.flutter_catalog"
- minSdkVersion 16
+ minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
@@ -99,11 +99,6 @@ dependencies {
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-auth:19.4.0'
implementation 'com.google.firebase:firebase-firestore:21.6.0'
- // Cf. https://firebase.google.com/docs/ml-kit/android/read-barcodes.
- implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
- implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.1'
- implementation 'com.google.firebase:firebase-ml-vision-image-label-model:20.0.1'
- implementation 'com.google.firebase:firebase-ml-vision-face-model:20.0.1'
}
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 95dd0e91..3e32ad2d 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -28,8 +28,8 @@
+ android:name="com.google.mlkit.vision.DEPENDENCIES"
+ android:value="ocr,ica,barcode,face" />
diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart
index be32f4b4..8baabd84 100644
--- a/lib/generated_plugin_registrant.dart
+++ b/lib/generated_plugin_registrant.dart
@@ -2,6 +2,7 @@
// Generated file. Do not edit.
//
+// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars
import 'package:cloud_firestore_web/cloud_firestore_web.dart';
diff --git a/lib/my_app_routes.dart b/lib/my_app_routes.dart
index eb4727bd..0f5e1336 100644
--- a/lib/my_app_routes.dart
+++ b/lib/my_app_routes.dart
@@ -1057,12 +1057,14 @@ const kMyAppRoutesAdvanced = [
},
),
MyRoute(
- child: FirebaseMLKitExample(),
+ child: GoogleMLKitExample(),
sourceFilePath: 'lib/routes/firebase_mlkit_ex.dart',
- title: 'Firebase ML Kit',
+ title: 'Google ML Kit',
description: 'Image labelling, text OCR, barcode scan, face detection.',
links: {
- 'Doc': 'https://pub.dartlang.org/packages/firebase_ml_vision',
+ 'pub.dev': 'https://pub.dev/packages/google_ml_kit',
+ 'MLKit doc':
+ 'https://developers.google.com/ml-kit/vision/text-recognition',
},
),
],
diff --git a/lib/routes/firebase_mlkit_ex.dart b/lib/routes/firebase_mlkit_ex.dart
index 32d60be8..88247ea6 100644
--- a/lib/routes/firebase_mlkit_ex.dart
+++ b/lib/routes/firebase_mlkit_ex.dart
@@ -1,26 +1,20 @@
import 'dart:io';
-import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:google_fonts/google_fonts.dart';
+import 'package:google_ml_kit/google_ml_kit.dart';
import 'package:image_picker/image_picker.dart';
import 'package:transparent_image/transparent_image.dart'
show kTransparentImage;
import 'package:flutter/material.dart';
-// NOTE: to add firebase support, first go to firebase console, generate the
-// firebase json file, and add configuration lines in the gradle files.
-// C.f. this commit: https://github.com/X-Wei/flutter_catalog/commit/48792cbc0de62fc47e0e9ba2cd3718117f4d73d1.
-
-// Adapted from the flutter firestore "babyname voter" codelab:
-// https://codelabs.developers.google.com/codelabs/flutter-firebase/#0
-class FirebaseMLKitExample extends StatefulWidget {
- const FirebaseMLKitExample({Key? key}) : super(key: key);
+class GoogleMLKitExample extends StatefulWidget {
+ const GoogleMLKitExample({Key? key}) : super(key: key);
@override
- _FirebaseMLKitExampleState createState() => _FirebaseMLKitExampleState();
+ _GoogleMLKitExampleState createState() => _GoogleMLKitExampleState();
}
-class _FirebaseMLKitExampleState extends State {
+class _GoogleMLKitExampleState extends State {
File? _imageFile;
String _mlResult = '';
final _picker = ImagePicker();
@@ -78,16 +72,14 @@ class _FirebaseMLKitExampleState extends State {
return;
}
String result = '';
- final FirebaseVisionImage visionImage =
- FirebaseVisionImage.fromFile(this._imageFile!);
- final ImageLabeler labelDetector = FirebaseVision.instance.imageLabeler();
- final List labels =
- await labelDetector.processImage(visionImage);
+ final InputImage inputImage = InputImage.fromFile(this._imageFile!);
+ final ImageLabeler imageLabeler = GoogleMlKit.vision.imageLabeler();
+ final List labels = await imageLabeler.processImage(inputImage);
result += 'Detected ${labels.length} labels.\n';
for (final ImageLabel label in labels) {
- final String text = label.text!;
- final String entityId = label.entityId!;
- final double confidence = label.confidence!;
+ final String text = label.label;
+ final int entityId = label.index;
+ final double confidence = label.confidence;
result +=
'\n#Label: $text($entityId), confidence=${confidence.toStringAsFixed(3)}';
}
@@ -102,20 +94,18 @@ class _FirebaseMLKitExampleState extends State {
return;
}
String result = '';
- final FirebaseVisionImage visionImage =
- FirebaseVisionImage.fromFile(this._imageFile!);
- final TextRecognizer textRecognizer =
- FirebaseVision.instance.textRecognizer();
- final VisionText visionText =
- await textRecognizer.processImage(visionImage);
- final String text = visionText.text!;
+ final InputImage inputImage = InputImage.fromFile(this._imageFile!);
+ final TextDetector textDetector = GoogleMlKit.vision.textDetector();
+ final RecognisedText recognizedText =
+ await textDetector.processImage(inputImage);
+ final String text = recognizedText.text;
debugPrint('Recognized text: "$text"');
- result += 'Detected ${visionText.blocks.length} text blocks.\n';
- for (final TextBlock block in visionText.blocks) {
- final Rect boundingBox = block.boundingBox!;
+ result += 'Detected ${recognizedText.blocks.length} text blocks.\n';
+ for (final TextBlock block in recognizedText.blocks) {
+ final Rect boundingBox = block.rect;
final List cornerPoints = block.cornerPoints;
- final String text = block.text!;
- final List languages = block.recognizedLanguages;
+ final String text = block.text;
+ final List languages = block.recognizedLanguages;
result += '\n# Text block:\n '
'bbox=$boundingBox\n '
'cornerPoints=$cornerPoints\n '
@@ -138,39 +128,20 @@ class _FirebaseMLKitExampleState extends State {
return;
}
String result = '';
- final FirebaseVisionImage visionImage =
- FirebaseVisionImage.fromFile(this._imageFile!);
- final BarcodeDetector barcodeDetector =
- FirebaseVision.instance.barcodeDetector();
+ final InputImage inputImage = InputImage.fromFile(this._imageFile!);
+ final BarcodeScanner barcodeScanner = GoogleMlKit.vision.barcodeScanner();
final List barcodes =
- await barcodeDetector.detectInImage(visionImage);
+ await barcodeScanner.processImage(inputImage);
result += 'Detected ${barcodes.length} barcodes.\n';
for (final Barcode barcode in barcodes) {
- final Rect boundingBox = barcode.boundingBox!;
- final List cornerPoints = barcode.cornerPoints;
-
- final String rawValue = barcode.rawValue!;
- final valueType = barcode.valueType;
+ final Rect boundingBox = barcode.value.boundingBox!;
+ final String rawValue = barcode.value.rawValue!;
+ final valueType = barcode.type;
result += '\n# Barcode:\n '
'bbox=$boundingBox\n '
- 'cornerPoints=$cornerPoints\n '
'rawValue=$rawValue\n '
- 'vlaueType=$valueType';
- // // See API reference for complete list of supported types
- // switch (valueType) {
- // case BarcodeValueType.wifi:
- // final String ssid = barcode.wifi.ssid;
- // final String password = barcode.wifi.password;
- // final BarcodeWiFiEncryptionType type = barcode.wifi.encryptionType;
- // break;
- // case BarcodeValueType.url:
- // final String title = barcode.url.title;
- // final String url = barcode.url.url;
- // break;
- // default:
- // break;
- // }
+ 'type=$valueType';
}
if (result.isNotEmpty) {
setState(() => this._mlResult = result);
@@ -183,16 +154,14 @@ class _FirebaseMLKitExampleState extends State {
return;
}
String result = '';
- final FirebaseVisionImage visionImage =
- FirebaseVisionImage.fromFile(this._imageFile!);
+ final InputImage inputImage = InputImage.fromFile(this._imageFile!);
const options = FaceDetectorOptions(
enableLandmarks: true,
enableClassification: true,
enableTracking: true,
);
- final FaceDetector faceDetector =
- FirebaseVision.instance.faceDetector(options);
- final List faces = await faceDetector.processImage(visionImage);
+ final FaceDetector faceDetector = GoogleMlKit.vision.faceDetector(options);
+ final List faces = await faceDetector.processImage(inputImage);
result += 'Detected ${faces.length} faces.\n';
for (final Face face in faces) {
final Rect boundingBox = face.boundingBox;
diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc
index 026851fa..f6f23bfe 100644
--- a/linux/flutter/generated_plugin_registrant.cc
+++ b/linux/flutter/generated_plugin_registrant.cc
@@ -2,6 +2,8 @@
// Generated file. Do not edit.
//
+// clang-format off
+
#include "generated_plugin_registrant.h"
#include
diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h
index 9bf74789..e0f0a47b 100644
--- a/linux/flutter/generated_plugin_registrant.h
+++ b/linux/flutter/generated_plugin_registrant.h
@@ -2,6 +2,8 @@
// Generated file. Do not edit.
//
+// clang-format off
+
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
diff --git a/pubspec.yaml b/pubspec.yaml
index d12139ba..00927887 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -34,7 +34,6 @@ dependencies:
day_night_switcher: ^0.2.0+1
edge_detection: ^1.0.6
english_words: ^4.0.0
- # cf. https://github.com/fluttercandies/extended_image/issues/309
extended_image: ^4.1.0
feature_discovery: ^0.14.0
ffi: ^1.1.2
@@ -45,11 +44,10 @@ dependencies:
firebase_core: ^1.4.0
firebase_core_web: ^1.1.0
firebase_database: ^7.1.2
- firebase_ml_vision: ^0.12.0+2
firebase_storage: ^10.0.1
firebase_storage_web: ^3.0.0
fl_chart: ^0.36.3
- flutter_bloc: ^7.0.1
+ flutter_bloc: ^7.1.0
flutter_gallery_assets: ^1.0.2
# flutter_gradients: ^1.0.0+2
flutter_markdown: ^0.6.2
@@ -61,6 +59,7 @@ dependencies:
fluttertoast: ^8.0.7
freezed_annotation: ^0.14.2
google_fonts: ^2.1.0
+ google_ml_kit: ^0.7.0
google_sign_in: ^5.0.5
graphview: ^1.0.0-nullsafety.1
hive: ^2.0.4