Search code examples
imageflutterdartflutter-image

Image saved by the app doesn't show up in the gallery


I trying to create a whatsapp status saver in flutter. I trying to save the whatsapp status. I created a folder statuses in /storage/emulated/0/statuses/ and The process of copying goes well. But that Image is not shown in the gallery app.

So I even Tried storing it in DCIM/Camera still it doesn't show up there. But when the copy the same image using file explorer then that image shows up in gallery app. I think something is wrong with the image properties.

The code used to save is here.

saveFile(filePath) async {
    String newFilename;
    File originalFile = File(filePath);
    Directory _directory = await getExternalStorageDirectory();
    if (!Directory("/storage/emulated/0/statuses/").existsSync()) {
      Directory("/storage/emulated/0/statuses/")
          .createSync(recursive: false);
    }
    String curDate = DateTime.now().toString();
    newFilename = "/storage/emulated/0/statuses/VIDEO-$curDate.jpg";

    await originalFile.copy(newFilename).then((value) {
      print("Saved: " + newFilename);
    });
  }

Solution

  • When you change a media, you should tell the device to re-scan. This image saver plugin will notify the Android OS about the media that is saved.

    If you don't want the plugin, you can use platform channels to write native code yourself.

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    This issue is discussed here and here.