Skip to content

Commit

Permalink
null-safety & deps up
Browse files Browse the repository at this point in the history
  • Loading branch information
piedcipher committed Jul 17, 2021
1 parent 4f34dcc commit fa681ed
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 120 deletions.
9 changes: 4 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 30

lintOptions {
disable 'InvalidPackage'
Expand All @@ -34,8 +34,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.wordpress.piedcipher.seefood"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -55,8 +55,7 @@ flutter {
}

dependencies {
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
implementation platform('com.google.firebase:firebase-bom:28.2.1')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
android:icon="@mipmap/ic_launcher">

<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="label" />
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="ica" />

<activity
android:name=".MainActivity"
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.8'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
147 changes: 70 additions & 77 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:google_ml_kit/google_ml_kit.dart';

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: true,
title: 'See Food',
theme: ThemeData(
primaryColor: Colors.deepPurple,
primaryColorDark: Colors.deepPurple[700],
Expand All @@ -27,25 +27,25 @@ class Home extends StatefulWidget {
}

class _HomeState extends State<Home> {
File _file;
String _labels;
bool _result;
XFile? _file;
String _labels = '';
bool _result = false;

void _openFilePicker() async {
var file = await ImagePicker.pickImage(source: ImageSource.gallery);
Future<void> _openFilePicker() async {
var file = await ImagePicker().pickImage(source: ImageSource.gallery);
setState(() {
_file = file;
});
_runMLKitOnDeviceImageLabeler();
await _runMLKitOnDeviceImageLabeler();
}

void _runMLKitOnDeviceImageLabeler() async {
FirebaseVisionImage firebaseVisionImage =
FirebaseVisionImage.fromFile(_file);
ImageLabeler imageLabeler = FirebaseVision.instance.imageLabeler();
Future<void> _runMLKitOnDeviceImageLabeler() async {
InputImage firebaseVisionImage = InputImage.fromFile(File(_file!.path));
ImageLabeler imageLabeler = GoogleMlKit.vision.imageLabeler();
List<ImageLabel> imageLabels =
await imageLabeler.processImage(firebaseVisionImage);
String labels = imageLabels.map((imageLabel) => imageLabel.text).join(", ");
String labels =
imageLabels.map((imageLabel) => imageLabel.label).join(', ');
setState(() {
_labels = labels;
if (_labels.contains("Food") ||
Expand All @@ -57,81 +57,74 @@ class _HomeState extends State<Home> {
setState(() {
_result = true;
});
} else {
setState(() {
_result = false;
});
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("See Food"),
actions: <Widget>[
_file != null
? IconButton(
onPressed: () {
setState(() {
_file = null;
});
},
icon: Icon(Icons.close),
)
: IconButton(
onPressed: () {
_openFilePicker();
},
icon: Icon(Icons.attach_file),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: _openFilePicker,
child: Icon(Icons.attach_file),
),
body: _file == null
? Column(
appBar: AppBar(
title: Text('See Food'),
actions: <Widget>[
_file != null
? IconButton(
onPressed: () {
setState(() {
_file = null;
});
},
icon: const Icon(Icons.close),
)
: IconButton(
onPressed: () async {
await _openFilePicker();
},
icon: const Icon(Icons.attach_file),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
await _openFilePicker();
},
child: const Icon(Icons.attach_file),
),
body: _file == null
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Center(
child: const Text('Click FAB to select an Image'),
),
],
)
: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
children: [
Container(
width: double.infinity,
color: _result ? Colors.green : Colors.red,
padding: const EdgeInsets.all(16.0),
margin: const EdgeInsets.symmetric(
vertical: 12.0,
horizontal: 12.0,
),
child: Text(
"Click FAB to select an Image",
_result
? "Yes! Image does contains food items.\n\n$_labels"
: "No! Image doesn't contain food items.\n\n$_labels",
style: const TextStyle(color: Colors.white),
),
),
Container(
margin: const EdgeInsets.all(12.0),
child: Image.file(File(_file!.path)),
),
],
)
: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FutureBuilder(
builder: (BuildContext buildContext,
AsyncSnapshot<dynamic> snapshot) =>
Container(
width: double.infinity,
color: _result ? Colors.green : Colors.red,
padding: EdgeInsets.all(16.0),
margin: EdgeInsets.symmetric(vertical: 12.0, horizontal: 12.0),
child: Text(
_result
? "Yes! Image does contains food items.\n\n$_labels"
: "No! Image doesn't contain food items.\n\n$_labels",
style: TextStyle(color: Colors.white),
),
),
),
Container(
margin: const EdgeInsets.all(12.0),
child: FutureBuilder(
builder: (BuildContext buildContext,
AsyncSnapshot<dynamic> snapshot) =>
Image.file(_file)),
),
],
),
));
),
),
);
}
}

0 comments on commit fa681ed

Please sign in to comment.