Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where do I need to store photo images in Flutter App?

Tags:

flutter

dart

I have an app that takes a photo.

I need that photo to be stored where all my assets/images/photos are.

So basically my question is : a) how can I find the path where these assets are (on the phone)? b) how can I add files to that same path?

Thanks


1 Answers

As per my knowledge you can not store image in assets package. Just because of when we build android/ios app after that assets folder is read only.

You need to store image in local mobile storage OR cloud OR catch memory

1) You can get storage path using :

  Future<String> getStorageDirectory() async {
    if (Platform.isAndroid) {
      return (await getExternalStorageDirectory()).path;  // OR return "/storage/emulated/0/Download";
    } else {
      return (await getApplicationDocumentsDirectory()).path;
    }
  }

2) Add image in path

createImage() async{
  String dir= getStorageDirectory();

  File directory = new File("$dir");
  if (directory.exists() != true) {
    directory.create();
  }
  File file = new File('$directory/image.jpeg');
  var newFile = await file.writeAsBytes(/* image bytes*/);
  await newFile.create();
}
like image 159
Sanjayrajsinh Avatar answered Sep 18 '25 19:09

Sanjayrajsinh