startImageStream method

  1. @override
Future<void> startImageStream(
  1. void onAvailable(
    1. CameraImageData? image
    ), {
  2. void onError(
    1. dynamic
    )?,
})
override

Implementation

@override
Future<void> startImageStream(
    void Function(CameraImageData? image) onAvailable,
    {void Function(dynamic)? onError}) async {
  events = eventChannel.receiveBroadcastStream().listen(
    (data) {
      if (data is Map) {
        onAvailable(
          CameraImageData(
            width: data['width'],
            height: data['height'],
            bytesPerRow: data['bytesPerRow'],
            bytes: Uint8List.fromList(data['data']),
          ),
        );
      } else if (onError != null) {
        onError(
          CameraMacOSException(
            code: "INVALID_FORMAT",
            message: "Stream data is not in a valid format",
            details: data,
          ),
        );
      }
    },
    onError: onError,
  );
}