Skip to content

Commit 2193261

Browse files
committed
let surface producer listen to orientation changes
1 parent 02c1207 commit 2193261

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/src/method_channel/mobile_scanner_method_channel.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart';
1414
import 'package:mobile_scanner/src/objects/barcode.dart';
1515
import 'package:mobile_scanner/src/objects/barcode_capture.dart';
1616
import 'package:mobile_scanner/src/objects/start_options.dart';
17+
import 'package:mobile_scanner/src/utils/parse_device_orientation_extension.dart';
1718

1819
/// An implementation of [MobileScannerPlatform] that uses method channels.
1920
class MethodChannelMobileScanner extends MobileScannerPlatform {
@@ -36,14 +37,32 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
3637
'dev.steenbakker.mobile_scanner/scanner/method',
3738
);
3839

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+
3946
/// The event channel that sends back scanned barcode events.
4047
@visibleForTesting
4148
final eventChannel = const EventChannel(
4249
'dev.steenbakker.mobile_scanner/scanner/event',
4350
);
4451

52+
Stream<DeviceOrientation>? _deviceOrientationStream;
4553
Stream<Map<Object?, Object?>>? _eventsStream;
4654

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+
4766
/// Get the event stream of barcode events that come from the [eventChannel].
4867
Stream<Map<Object?, Object?>> get eventsStream {
4968
_eventsStream ??=
@@ -296,6 +315,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
296315
startResult,
297316
startOptions.cameraDirection,
298317
);
318+
_surfaceProducerDelegate?.startListeningToDeviceOrientation(
319+
deviceOrientationChangedStream,
320+
);
299321
}
300322

301323
final int? numberOfCameras = startResult['numberOfCameras'] as int?;

0 commit comments

Comments
 (0)