diff --git a/example/lib/main_live.dart b/example/lib/main_live.dart index b4d7b5b..aaeec99 100644 --- a/example/lib/main_live.dart +++ b/example/lib/main_live.dart @@ -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()); @@ -40,25 +41,48 @@ class _MyHomePageState extends State { body: Stack( fit: StackFit.expand, children: [ - CameraMlVision>( - 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>( + 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( diff --git a/example/pubspec.lock b/example/pubspec.lock index 3f98b8e..24f7f0f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 61d2aa0..620397e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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: ../