3

I need to create an examination application in Flutter, where we need to take photograph and video of a user at some intervals, And while doing this we don't want to show the camera screen.

I tried to use Camera plugin of Flutter, but I am not able to find any way to capture image and video without camera preview.

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';

List<CameraDescription> cameras;

Future<void> main() async {
  cameras = await availableCameras();
  runApp(CameraApp());
}

class CameraApp extends StatefulWidget {
  @override
  _CameraAppState createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
  CameraController controller;

  @override
  void initState() {
    super.initState();
    controller = CameraController(cameras[0], ResolutionPreset.medium);
    controller.initialize().then((_) {
      if (!mounted) {
        return;
      }
      setState(() {});
    });
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (!controller.value.isInitialized) {
      return Container();
    }
    return AspectRatio(
        aspectRatio:
        controller.value.aspectRatio,
        child: CameraPreview(controller));
  }
}

I want not to show the preview screen and take the images or videos at some interval

Pawanpreet Singh
  • 229
  • 5
  • 12

1 Answers1

3

While accessing the Camera in the background was possible on earlier iterations of Android. Since Android P, accessing sensors like Camera and Mic can only be done while the app is in the foreground. More details can be read here.

Omatt
  • 8,564
  • 2
  • 42
  • 144