Browse Source

fixed multi result code positions in android

pull/76/head
Khoren Markosyan 2 years ago
parent
commit
f9d4dede22
  1. 1
      example/lib/main.dart
  2. 10
      example/pubspec.lock
  3. 37
      lib/src/ui/multi_result_overlay.dart
  4. 1
      lib/src/ui/reader_widget.dart
  5. 37
      zxscanner/pubspec.lock

1
example/lib/main.dart

@ -43,7 +43,6 @@ class _DemoPageState extends State<DemoPage> {
Code? result; Code? result;
Codes? multiResult; Codes? multiResult;
// Currently code positions works incorrect on Android in Portrait mode
bool isMultiScan = false; bool isMultiScan = false;
bool showDebugInfo = true; bool showDebugInfo = true;

10
example/pubspec.lock

@ -35,21 +35,21 @@ packages:
name: camera_android name: camera_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.10.2" version: "0.10.2+1"
camera_avfoundation: camera_avfoundation:
dependency: transitive dependency: transitive
description: description:
name: camera_avfoundation name: camera_avfoundation
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.10" version: "0.9.10+1"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: camera_platform_interface name: camera_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.3.2" version: "2.3.3"
camera_web: camera_web:
dependency: transitive dependency: transitive
description: description:
@ -148,7 +148,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "1.0.0-beta.7" version: "1.0.0-beta.8"
font_awesome_flutter: font_awesome_flutter:
dependency: "direct main" dependency: "direct main"
description: description:
@ -359,4 +359,4 @@ packages:
version: "6.1.0" version: "6.1.0"
sdks: sdks:
dart: ">=2.18.0 <3.0.0" dart: ">=2.18.0 <3.0.0"
flutter: ">=3.0.0" flutter: ">=3.3.0"

37
lib/src/ui/multi_result_overlay.dart

@ -1,6 +1,9 @@
import 'dart:ui'; import 'dart:ui';
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../flutter_zxing.dart'; import '../../flutter_zxing.dart';
@ -9,24 +12,46 @@ class MultiResultOverlay extends StatelessWidget {
super.key, super.key,
this.results = const <Code>[], this.results = const <Code>[],
this.onCodeTap, this.onCodeTap,
this.controller,
}); });
final List<Code> results; final List<Code> results;
final Function(Code code)? onCodeTap; final Function(Code code)? onCodeTap;
final CameraController? controller;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Positioned.fill( return Positioned.fill(
child: CustomPaint( child: RotatedBox(
painter: MultiScanPainter( quarterTurns: _getQuarterTurns(),
context: context, child: CustomPaint(
codes: results, painter: MultiScanPainter(
color: Theme.of(context).primaryColor, context: context,
onCodeTap: onCodeTap, codes: results,
color: Theme.of(context).primaryColor,
onCodeTap: onCodeTap,
),
), ),
), ),
); );
} }
int _getQuarterTurns() {
if (defaultTargetPlatform != TargetPlatform.android) {
return 0;
}
final Map<DeviceOrientation, int> turns = <DeviceOrientation, int>{
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 { class MultiScanPainter extends CustomPainter {

1
lib/src/ui/reader_widget.dart

@ -293,6 +293,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
? MultiResultOverlay( ? MultiResultOverlay(
results: results.codes, results: results.codes,
onCodeTap: widget.onScan, onCodeTap: widget.onScan,
controller: controller,
) )
: null, : null,
), ),

37
zxscanner/pubspec.lock

@ -98,7 +98,7 @@ packages:
name: built_value name: built_value
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.4.2" version: "8.4.3"
camera: camera:
dependency: transitive dependency: transitive
description: description:
@ -112,21 +112,21 @@ packages:
name: camera_android name: camera_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.10.2" version: "0.10.2+1"
camera_avfoundation: camera_avfoundation:
dependency: transitive dependency: transitive
description: description:
name: camera_avfoundation name: camera_avfoundation
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.10" version: "0.9.10+1"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: camera_platform_interface name: camera_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.3.2" version: "2.3.3"
camera_web: camera_web:
dependency: transitive dependency: transitive
description: description:
@ -318,10 +318,10 @@ packages:
flutter_zxing: flutter_zxing:
dependency: "direct main" dependency: "direct main"
description: description:
path: ".." name: flutter_zxing
relative: true url: "https://pub.dartlang.org"
source: path source: hosted
version: "1.0.0-beta.7" version: "0.10.0"
font_awesome_flutter: font_awesome_flutter:
dependency: "direct main" dependency: "direct main"
description: description:
@ -524,7 +524,7 @@ packages:
name: mime name: mime
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.3" version: "1.0.4"
mobx: mobx:
dependency: "direct main" dependency: "direct main"
description: description:
@ -587,7 +587,7 @@ packages:
name: path_provider_macos name: path_provider_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.6" version: "2.0.7"
path_provider_platform_interface: path_provider_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -685,7 +685,7 @@ packages:
name: shared_preferences name: shared_preferences
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.15" version: "2.0.16"
shared_preferences_android: shared_preferences_android:
dependency: transitive dependency: transitive
description: description:
@ -693,10 +693,10 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.14" version: "2.0.14"
shared_preferences_ios: shared_preferences_foundation:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_ios name: shared_preferences_foundation
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
@ -707,13 +707,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" 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: shared_preferences_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -921,7 +914,7 @@ packages:
name: web_socket_channel name: web_socket_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.0" version: "2.3.0"
win32: win32:
dependency: transitive dependency: transitive
description: description:
@ -935,7 +928,7 @@ packages:
name: xdg_directories name: xdg_directories
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0+2" version: "0.2.0+3"
xml: xml:
dependency: transitive dependency: transitive
description: description:

Loading…
Cancel
Save