1

I’m building a Flutter app where the user can take pictures of objects, but I want the capture button to be enabled only when the camera is at a specific distance from the object.

I am using the camera plugin to get the live preview, and some logic to estimate the distance of the object in front of the camera.

Here’s the simplified workflow:

  1. Show live camera preview.

  2. Continuously estimate distance from the camera to the object.

  3. Enable the capture button only when the distance is within a target range.

  4. Capture and save/crop the image when allowed.

if (_capturedImage == null && _isCameraInitialized)
              ElevatedButton(
                onPressed: _captureImage,
                child: const Text('Capture Image'),
              ),


Future<void> _captureImage() async {
  if (!_isCameraInitialized || _cameraController == null) return;

  final XFile file = await _cameraController!.takePicture();

  final croppedFile = await cropToOverlay(File(file.path), scanSquareSize, context);

  setState(() {
    _capturedImage = croppedFile;
    _uploadedImageUrl = null;
    _detections = null;
  });
}

How can I reliably measure distance to an object and enable the capture button only when the distance is within a specific range in Flutter?

2
  • 2
    you have to use depth detection model in your app. Commented Nov 12 at 10:27
  • 2
    I am experimenting with tflite_flutter. Is it possible to achieve my intended outcome using this framework? Commented Nov 12 at 12:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.