0

I have a picture on the application interface that will be modified by drag and drop, is there a way in the flutter to save on the device after editing when I press the button?

@override
  Widget build(BuildContext context) {
    final animation = Tween<double>(begin: 0, end: 1).animate(_controller);
    return Scaffold(
        body: Container(
      width: double.infinity,
      height: double.infinity,
      color: Colors.white,
      child: Stack(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(top: 40),
            alignment: Alignment.topCenter,
            child: Column(
              children: <Widget>[
                Image.asset('image/07.png', width: 400, height: 400),
              ],
            ),
          ),
Amer Kanjo
  • 15
  • 5

1 Answers1

1

The below blog will help you in saving data locally in Flutter

https://flutter.dev/docs/cookbook/persistence/reading-writing-files

Please use SharedPreferences if your requirement does not include externally accessing the photo/file.

https://pub.dev/packages/shared_preferences

If you want a quick answer:

The File class needs a copy method, which you can be used to copy the file (which is already saved on disk by either the camera or by lying in gallery) and put it into your application documents directory:

// using your method of getting an image

    final File image = await ImagePicker.pickImage(source: imageSource);

// getting a directory path for saving
final String path = await getApplicationDocumentsDirectory().path;

// copy the file to a new path
final File newImage = await image.copy('$path/image1.png');

setState(() {
  _image = newImage;
});

You should also note that you can get the path of the image file from ImagePicker using image.path, which will also contain the file ending that you might want to extract and you can save your image path by using newImage.path.

Source : https://stackoverflow.com/a/51338178/10104608

Mohit Shetty
  • 1,551
  • 8
  • 26