I'm using this lib for displaying a camera (https://pub.dev/packages/camera), however, I'd like to set a predefined zoom value for the camera before it starts, but I'm not able to identify where I can set it using this lib.
Does anyone know how to do it?
Here's the code I got so far
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
class CameraPage extends StatefulWidget {
@override
_CameraPageState createState() => _CameraPageState();
}
class _CameraPageState extends State<CameraPage> {
List<CameraDescription> cameras;
CameraController controller;
@override
void initState() {
// TODO: implement initState
super.initState();
buscarCameras();
}
Future<void> buscarCameras() async {
cameras = await availableCameras();
controller = CameraController(cameras[0], ResolutionPreset.medium);
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
});
}
@override
Widget build(BuildContext context) {
if(controller == null || controller.value == null)
return Center(
child: CircularProgressIndicator(),
);
if (!controller.value.isInitialized) {
return Container();
}
return AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: CameraPreview(controller));
}
}
Flutter has added zoom support as of Camera version 0.6.2. You can use cameraController.setZoomLevel(4.0);
in your code to adjust the zoom level.
There are also other helpful functions, such as cameraControl.getMaxZoomLevel();
to find the limits for the zoom level.
There isn't any documentation for this feature at time of writing, as it is very recent, but you can look through the code for the camera controller to see the available methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With