Flutter Image form Image Picker to Document Path

206 Views Asked by At

I am creating an app that saves images locally through sqflite, I have soon found out that the images are being saved as temp which means that it will be deleted by the device and i'm not able to retrieve those images anymore. I have been coding to save it to the document directory of the app but it seems to fail and throw error

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot copy file to '/data/user/0/com.example.e4psmap/cache/scaled_0d5d5070-70da-4f42-9055-c31a6ed8d3d51761448072222030817.jpg', path = '/data/user/0/com.example.e4psmap/app_flutter/scaled_0d5d5070-70da-4f42-9055-c31a6ed8d3d51761448072222030817.jpg' (OS Error: No such file or directory, errno = 2)

this is my code:

void getpic(ImageSource src) async{
    Uint8List byte;
    final picfile = await _imagepicker.getImage(
      source: src, imageQuality: 25
    );
    if(picfile != null){
      Directory appDir = await getApplicationDocumentsDirectory();
      String appdoc = appDir.path;
      final filename = path.basename(picfile.path);
      final local = File('${appdoc}/$filename');
      final lclfile = await local.copy(picfile.path);
    }
    // converted = picfile!.path;
    // setState(() {
    //   _imgfile = picfile!;
    // });
    Navigator.pop(context);
  }

Anyone knows why I am having this errors, and any fix for this error, Thank you

1

There are 1 best solutions below

0
On

If you replace final with the corresponding class, the error will be very obvious.