0

This is the error when using the copy function. How do I save the image clicked from the camera?

Future _takePicture() async {
    final imageFile = await ImagePicker().getImage(
      source: ImageSource.camera,
      maxHeight: 600,
    );
    setState(() {
      _storedImage = File(imageFile.path);
    });
    final appDir = await syspaths.getApplicationDocumentsDirectory();
    final fileName = path.basename(imageFile.path);
    final savedImage = await imageFile.copy('${appDir.path}/$fileName');
  }
Mihail Duchev
  • 4,691
  • 10
  • 25
  • 32

1 Answers1

3

you should copy _storedImage instead of imageFile

imageFile type is PickedFile and hasn't copy method

Future _takePicture() async {
        final imageFile = await ImagePicker().getImage(
          source: ImageSource.camera,
          maxHeight: 600,
        );
        setState(() {
          _storedImage = File(imageFile.path);
        });
        final appDir = await syspaths.getApplicationDocumentsDirectory();
        final fileName = path.basename(imageFile.path);
        final savedImage = await _storedImage.copy('${appDir.path}/$fileName');
      }
Amir
  • 2,225
  • 2
  • 18
  • 27