diff --git a/example/lib/main.dart b/example/lib/main.dart index 6e4dc0c..63a172b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -43,7 +43,6 @@ class _DemoPageState extends State { Code? result; Codes? multiResult; - // Currently code positions works incorrect on Android in Portrait mode bool isMultiScan = false; bool showDebugInfo = true; diff --git a/example/pubspec.lock b/example/pubspec.lock index 8763bb4..2500a6c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -35,21 +35,21 @@ packages: name: camera_android url: "https://pub.dartlang.org" source: hosted - version: "0.10.2" + version: "0.10.2+1" camera_avfoundation: dependency: transitive description: name: camera_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "0.9.10" + version: "0.9.10+1" camera_platform_interface: dependency: transitive description: name: camera_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.3.2" + version: "2.3.3" camera_web: dependency: transitive description: @@ -148,7 +148,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0-beta.7" + version: "1.0.0-beta.8" font_awesome_flutter: dependency: "direct main" description: @@ -359,4 +359,4 @@ packages: version: "6.1.0" sdks: dart: ">=2.18.0 <3.0.0" - flutter: ">=3.0.0" + flutter: ">=3.3.0" diff --git a/lib/src/ui/multi_result_overlay.dart b/lib/src/ui/multi_result_overlay.dart index 77bd744..4a71860 100644 --- a/lib/src/ui/multi_result_overlay.dart +++ b/lib/src/ui/multi_result_overlay.dart @@ -1,6 +1,9 @@ import 'dart:ui'; +import 'package:camera/camera.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import '../../flutter_zxing.dart'; @@ -9,24 +12,46 @@ class MultiResultOverlay extends StatelessWidget { super.key, this.results = const [], this.onCodeTap, + this.controller, }); final List results; final Function(Code code)? onCodeTap; + final CameraController? controller; @override Widget build(BuildContext context) { return Positioned.fill( - child: CustomPaint( - painter: MultiScanPainter( - context: context, - codes: results, - color: Theme.of(context).primaryColor, - onCodeTap: onCodeTap, + child: RotatedBox( + quarterTurns: _getQuarterTurns(), + child: CustomPaint( + painter: MultiScanPainter( + context: context, + codes: results, + color: Theme.of(context).primaryColor, + onCodeTap: onCodeTap, + ), ), ), ); } + + int _getQuarterTurns() { + if (defaultTargetPlatform != TargetPlatform.android) { + return 0; + } + final Map turns = { + DeviceOrientation.portraitUp: 1, + DeviceOrientation.landscapeRight: 2, + DeviceOrientation.portraitDown: 1, + DeviceOrientation.landscapeLeft: 0, + }; + return turns[_getApplicableOrientation()]!; + } + + DeviceOrientation _getApplicableOrientation() { + return controller?.value.deviceOrientation ?? DeviceOrientation.portraitUp; + } } class MultiScanPainter extends CustomPainter { diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index f8f20b1..2aa2ba9 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -293,6 +293,7 @@ class _ReaderWidgetState extends State ? MultiResultOverlay( results: results.codes, onCodeTap: widget.onScan, + controller: controller, ) : null, ), diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index 8879ce6..fd64a70 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -98,7 +98,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.2" + version: "8.4.3" camera: dependency: transitive description: @@ -112,21 +112,21 @@ packages: name: camera_android url: "https://pub.dartlang.org" source: hosted - version: "0.10.2" + version: "0.10.2+1" camera_avfoundation: dependency: transitive description: name: camera_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "0.9.10" + version: "0.9.10+1" camera_platform_interface: dependency: transitive description: name: camera_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.3.2" + version: "2.3.3" camera_web: dependency: transitive description: @@ -318,10 +318,10 @@ packages: flutter_zxing: dependency: "direct main" description: - path: ".." - relative: true - source: path - version: "1.0.0-beta.7" + name: flutter_zxing + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.0" font_awesome_flutter: dependency: "direct main" description: @@ -524,7 +524,7 @@ packages: name: mime url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" mobx: dependency: "direct main" description: @@ -587,7 +587,7 @@ packages: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.0.7" path_provider_platform_interface: dependency: transitive description: @@ -685,7 +685,7 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "2.0.15" + version: "2.0.16" shared_preferences_android: dependency: transitive description: @@ -693,10 +693,10 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.14" - shared_preferences_ios: + shared_preferences_foundation: dependency: transitive description: - name: shared_preferences_ios + name: shared_preferences_foundation url: "https://pub.dartlang.org" source: hosted version: "2.1.1" @@ -707,13 +707,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" - shared_preferences_macos: - dependency: transitive - description: - name: shared_preferences_macos - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" shared_preferences_platform_interface: dependency: transitive description: @@ -921,7 +914,7 @@ packages: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.3.0" win32: dependency: transitive description: @@ -935,7 +928,7 @@ packages: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+2" + version: "0.2.0+3" xml: dependency: transitive description: