snapshot method

Future<bool> snapshot()

Implementation

Future<bool> snapshot() async {
  bool ok = true;

  try {
    if (cameras != null &&
        cameras!.isNotEmpty &&
        controller != null &&
        controller!.value.isInitialized &&
        widget.model.busy != true) {
      // set busy
      widget.model.busy = true;

      // disable shutter
      if (shutterbutton != null) {
        shutterbutton!.model.color = Colors.lightGreenAccent;
        shutterbutton!.model.size = 60;
      }

      // stop stream
      if (widget.model.stream) controller?.stopImageStream();

      /// take picture
      XFile image = await controller!.takePicture();

      // start stream
      if (widget.model.stream) {
        await controller?.startImageStream(
            (stream) => onStream(stream, cameras![widget.model.index ?? 0]));
      }

      // save the image
      ok = await onSnapshot(image);

      // enable shutter
      if (shutterbutton != null) {
        shutterbutton!.model.color = Colors.white;
        shutterbutton!.model.size = 65;
      }

      widget.model.busy = false;
    } else {
      ok = false;
      widget.model.onFail(Data(), message: "Failed to take picture");
      Log().debug('Unable to take a snapshot');
    }
  } catch (e) {
    ok = false;
    Log().exception(e);
    widget.model.busy = false;
  }

  return ok;
}