@@ -19,7 +19,8 @@ export 'package:camera/camera.dart';
1919part 'utils.dart' ;
2020
2121typedef HandleDetection <T > = Future <T > Function (FirebaseVisionImage image);
22- typedef ErrorWidgetBuilder = Widget Function (BuildContext context, CameraError error);
22+ typedef ErrorWidgetBuilder = Widget Function (
23+ BuildContext context, CameraError error);
2324
2425enum CameraError {
2526 unknown,
@@ -111,7 +112,6 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
111112 } on PlatformException catch (e) {
112113 debugPrint ('$e ' );
113114 }
114-
115115 }
116116 }
117117
@@ -174,6 +174,34 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
174174 return image;
175175 }
176176
177+ Future <void > flash (FlashMode mode) async {
178+ await _cameraController! .setFlashMode (mode);
179+ }
180+
181+ Future <void > focus (FocusMode mode) async {
182+ await _cameraController! .setFocusMode (mode);
183+ }
184+
185+ Future <void > focusPoint (Offset point) async {
186+ await _cameraController! .setFocusPoint (point);
187+ }
188+
189+ Future <void > zoom (double zoom) async {
190+ await _cameraController! .setZoomLevel (zoom);
191+ }
192+
193+ Future <void > exposure (ExposureMode mode) async {
194+ await _cameraController! .setExposureMode (mode);
195+ }
196+
197+ Future <void > exposureOffset (double offset) async {
198+ await _cameraController! .setExposureOffset (offset);
199+ }
200+
201+ Future <void > exposurePoint (Offset offset) async {
202+ await _cameraController! .setExposurePoint (offset);
203+ }
204+
177205 Future <void > _initialize () async {
178206 if (Platform .isAndroid) {
179207 final deviceInfo = DeviceInfoPlugin ();
@@ -267,22 +295,25 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
267295 : widget.errorBuilder !(context, _cameraError);
268296 }
269297
270- Widget cameraPreview = AspectRatio (
271- aspectRatio: _cameraController! .value.isInitialized ? _cameraController!
272- .value.aspectRatio : 1 ,
273- child: _isStreaming
274- ? CameraPreview (
275- _cameraController! ,
276- )
277- : _getPicture (),
278- );
298+ var cameraPreview = _isStreaming
299+ ? CameraPreview (
300+ _cameraController! ,
301+ )
302+ : _getPicture ();
279303
280304 if (widget.overlayBuilder != null ) {
281305 cameraPreview = Stack (
282306 fit: StackFit .passthrough,
283307 children: [
284308 cameraPreview,
285- widget.overlayBuilder !(context),
309+ (cameraController? .value.isInitialized ?? false )
310+ ? AspectRatio (
311+ aspectRatio: _isLandscape ()
312+ ? cameraController! .value.aspectRatio
313+ : (1 / cameraController! .value.aspectRatio),
314+ child: widget.overlayBuilder !(context),
315+ )
316+ : Container (),
286317 ],
287318 );
288319 }
@@ -299,25 +330,28 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
299330 }
300331 },
301332 key: _visibilityKey,
302- child: FittedBox (
303- alignment: Alignment .center,
304- fit: BoxFit .cover,
305- child: SizedBox (
306- width: _cameraController! .value.previewSize! .height *
307- _cameraController! .value.aspectRatio,
308- height: _cameraController! .value.previewSize! .height,
309- child: cameraPreview,
310- ),
311- ),
333+ child: cameraPreview,
312334 );
313335 }
314336
337+ DeviceOrientation ? _getApplicableOrientation () {
338+ return (cameraController? .value.isRecordingVideo ?? false )
339+ ? cameraController? .value.recordingOrientation
340+ : (cameraController? .value.lockedCaptureOrientation ??
341+ cameraController? .value.deviceOrientation);
342+ }
343+
344+ bool _isLandscape () {
345+ return [DeviceOrientation .landscapeLeft, DeviceOrientation .landscapeRight]
346+ .contains (_getApplicableOrientation ());
347+ }
348+
315349 void _processImage (CameraImage cameraImage) async {
316350 if (! _alreadyCheckingImage && mounted) {
317351 _alreadyCheckingImage = true ;
318352 try {
319353 final results =
320- await _detect <T >(cameraImage, widget.detector, _rotation! );
354+ await _detect <T >(cameraImage, widget.detector, _rotation! );
321355 widget.onResult (results);
322356 } catch (ex, stack) {
323357 debugPrint ('$ex , $stack ' );
0 commit comments