I have created a function that created folders in my external directory. After that, I am downloading an image from the internet and saving it to the "Gallery Images" folder. The image is being saved in the folder but it is not visible in the galley. Am I missing something?
Code:
void createFolder() async {
String directory = (await p.getExternalStorageDirectory()).path;
List<String> externalPathList = directory.split('/');
int posOfAndroidDir = externalPathList.indexOf('Android');
String rootPath = externalPathList.sublist(0, posOfAndroidDir + 1).join('/');
final path = Directory("$rootPath/Gallery");
var storageStatus = await Permission.storage.status;
var externalStorageStatus = await Permission.manageExternalStorage.status;
if (!storageStatus.isGranted) {
await Permission.storage.request();
}
if (!externalStorageStatus.isGranted) {
await Permission.manageExternalStorage.request();
}
if ((await path.exists())) {
print("exists");
print(path.path.toString());
} else {
var value = await path.create();
print("create success");
print(value.path.toString());
await Directory(rootPath + "/Gallery" + "/Gallery Images").create(recursive: true);
await Directory(rootPath + "/Gallery" + "/Gallery Video").create(recursive: true);
await Directory(rootPath + "/Gallery" + "/Gallery Documents").create(recursive: true);
await Directory(rootPath + "/Gallery" + "/Gallery Audio").create(recursive: true);
await Directory(rootPath + "/Gallery" + "/Gallery Voice Notes").create(recursive: true);
await Directory(rootPath + "/Gallery" + "/.thumbnails").create(recursive: true);
await Dio().download(url, rootPath + "/Gallery" + "/Gallery Images", onReceiveProgress: (int sent, int total) {
final progress = (sent / total) * 100;
print('image download progress: $progress');
});
}
}