Untitled

 avatar
unknown
plain_text
a year ago
1.7 kB
4
Indexable
void _onCapturePressed(context) async {
    // kLog(widget.title);

    final targetPath = (await getTemporaryDirectory()).path + '${DateTime.now()}.jpg';

    try {
      setState(() {
        isCaptured = true;
      });
      // var image = File(path);
      XFile picture = await cameraController.takePicture();
      await picture.saveTo(targetPath);

      File? image = await compressCameraImageAndGetFile(picture, targetPath);
      // File? image = await File(targetPath);

      if (widget.title == 'assignTask') {
        push(CameraViewPage(
          path: image!.path,
          path1: image,
          title: widget.title!,
        ));
        // assignTaskC.imagefiles.add(image);
      }
      if (widget.title == 'reportanincident') {
        if (shoutC.selectedSubCategory.value!.aiModelUploaded && shoutC.selectedSubCategory.value!.aiValidationApplied) {
          // kLog('********************nah*************');
          await aiModelC.imageRecognition(imagePath: image!.path, context: context);
          // if (widget.title != 'assignTask')
          //shoutC.imagefiles.add(image);
        } else {
          // kLog('********************ggg*************');
          push(
            CameraViewPage(
              path: image!.path,
              path1: image,
              title: widget.title!,
            ),
          );

          // if (widget.title != 'assignTask') shoutC.imagefiles.add(image);
        }
      }
      setState(() {
        isCaptured = false;
      });
    } catch (e) {
      setState(() {
        isCaptured = false;
      });
      // If an error occurs, log the error to the console.
      kLog(e);
    }
  }
Editor is loading...
Leave a Comment