Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions example/lib/main_live.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
import 'package:native_device_orientation/native_device_orientation.dart';

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

Expand Down Expand Up @@ -40,25 +41,48 @@ class _MyHomePageState extends State<MyHomePage> {
body: Stack(
fit: StackFit.expand,
children: [
CameraMlVision<List<Barcode>>(
key: _scanKey,
detector: detector.detectInImage,
resolution: ResolutionPreset.high,
onResult: (barcodes) {
if (barcodes == null ||
barcodes.isEmpty ||
data.contains(barcodes.first.displayValue) ||
!mounted) {
return;
}
setState(() {
data.add(barcodes.first.displayValue);
});
},
onDispose: () {
detector.close();
},
),
NativeDeviceOrientationReader(builder: (context) {
NativeDeviceOrientation orientation =
NativeDeviceOrientationReader.orientation(context);

int turns;
switch (orientation) {
case NativeDeviceOrientation.landscapeLeft:
turns = -1;
break;
case NativeDeviceOrientation.landscapeRight:
turns = 1;
break;
case NativeDeviceOrientation.portraitDown:
turns = 2;
break;
default:
turns = 0;
break;
}

return RotatedBox(
quarterTurns: turns,
child: CameraMlVision<List<Barcode>>(
key: _scanKey,
detector: detector.detectInImage,
resolution: ResolutionPreset.high,
onResult: (barcodes) {
if (barcodes == null ||
barcodes.isEmpty ||
data.contains(barcodes.first.displayValue) ||
!mounted) {
return;
}
setState(() {
data.add(barcodes.first.displayValue);
});
},
onDispose: () {
detector.close();
},
));
}),
Container(
alignment: Alignment.bottomCenter,
child: Column(
Expand Down
9 changes: 8 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
native_device_orientation:
dependency: "direct main"
description:
name: native_device_orientation
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -232,7 +239,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.15"
typed_data:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
native_device_orientation: ^0.3.0
flutter_camera_ml_vision:
path: ../

Expand Down