@@ -14,6 +14,7 @@ import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart';
14
14
import 'package:mobile_scanner/src/objects/barcode.dart' ;
15
15
import 'package:mobile_scanner/src/objects/barcode_capture.dart' ;
16
16
import 'package:mobile_scanner/src/objects/start_options.dart' ;
17
+ import 'package:mobile_scanner/src/utils/parse_device_orientation_extension.dart' ;
17
18
18
19
/// An implementation of [MobileScannerPlatform] that uses method channels.
19
20
class MethodChannelMobileScanner extends MobileScannerPlatform {
@@ -36,14 +37,32 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
36
37
'dev.steenbakker.mobile_scanner/scanner/method' ,
37
38
);
38
39
40
+ /// The event channel that sends back device orientation change events.
41
+ @visibleForTesting
42
+ final deviceOrientationEventChannel = const EventChannel (
43
+ 'dev.steenbakker.mobile_scanner/scanner/deviceOrientation' ,
44
+ );
45
+
39
46
/// The event channel that sends back scanned barcode events.
40
47
@visibleForTesting
41
48
final eventChannel = const EventChannel (
42
49
'dev.steenbakker.mobile_scanner/scanner/event' ,
43
50
);
44
51
52
+ Stream <DeviceOrientation >? _deviceOrientationStream;
45
53
Stream <Map <Object ?, Object ?>>? _eventsStream;
46
54
55
+ /// Get the event stream of device orientation change events
56
+ /// that come from the [deviceOrientationEventChannel] .
57
+ Stream <DeviceOrientation > get deviceOrientationChangedStream {
58
+ _deviceOrientationStream ?? = deviceOrientationEventChannel
59
+ .receiveBroadcastStream ()
60
+ .cast <String >()
61
+ .map ((String orientation) => orientation.parseDeviceOrientation ());
62
+
63
+ return _deviceOrientationStream! ;
64
+ }
65
+
47
66
/// Get the event stream of barcode events that come from the [eventChannel] .
48
67
Stream <Map <Object ?, Object ?>> get eventsStream {
49
68
_eventsStream ?? =
@@ -296,6 +315,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
296
315
startResult,
297
316
startOptions.cameraDirection,
298
317
);
318
+ _surfaceProducerDelegate? .startListeningToDeviceOrientation (
319
+ deviceOrientationChangedStream,
320
+ );
299
321
}
300
322
301
323
final int ? numberOfCameras = startResult['numberOfCameras' ] as int ? ;
0 commit comments