skip to Main Content

I’m confused I’ve taken a picture but can’t save it to the phone.How should I save pictures to the phone?

I used the following code to take a picture.

ValueNotifier<XFile?>_imageFile=ValueNotifier(null);

ImagePicker _imagePicker=ImagePicker();

Future<void> _getImage(ImageSource imageSource) async{
    XFile? imgFile=await _imagePicker.pickImage(source: imageSource);
    _imageFile.value=imgFile;
  }

2

Answers


  1. This is another aproach to save your picked image:

    final XFile? pickedFile = await _imagePicker.pickImage(source: imageSource);
    new File(pathToSaveHere).writeAsBytesSync(await pickedFile!.readAsBytes());
    

    about "pathToSaveHere" you can use "path_provider" plugin of flutter https://pub.dev/packages/path_provider. It provide severeal methods to get paths you are able to save. Note that: due permissions restrictions you CANNOT save everywhere.

    Login or Signup to reply.
  2. First add gallery_saver package then call this function,

    void _takePhoto() async {
        final _pickedImg= await ImagePicker.pickImage(source: 
           ImageSource.camera)
             .then((File recordedImage) {
                // saving the picked Image to Gallery
                if (recordedImage != null && recordedImage.path != null) {
                GallerySaver.saveImage(recordedImage.path);
                setState(() {});
          }});
       // ur picked image in File form 
       File? img = File(_pickedImg!.path);
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search