I'm trying to get a list of files in my app's documents directory using path_provider
and getApplicationDocumentsDirectory()
along with Directory(appFolder).listSync()
from dart:io
. While I can load the image files from this directory and view them using flutter's Image.file
function, I cannot see any of the image/jpg files generated by my app in the directory listing. I've also tried loading the files using File(imagePath)
with the same result.
I cannot understand why Image.File(imagePath)
can find, load and display the image file successfully while running File(imagePath)
gives an OS Error: No such file or directory
. For additional context - these files are being generated using the camera
package for flutter. I'm seeing this on Android so far (have not testing this on iOS yet).
Code previews
Code to get appFolder in both cases
import 'package:provider/provider.dart';
final dbFolder = await getApplicationDocumentsDirectory();
Code to display the images
import 'package:flutter/material.dart';
// just the relevant code to display the image
Center(
child: Image.file(Platform.isIOS
? File(appFolder + '/' + imagePath)
: File(appFolder + imagePath)),
),
Code to list the files in the folder
import 'dart:io';
void _getDirectoryList() async {
fileList = Directory(appFolder).listSync(followLinks: true);
final List<FileSystemEntity> entities =
await Directory(appFolder).list().toList();
entities.forEach(print);
}
I'm doing all this to create an archive of the app db and user generated image files, but have gotten stuck at not finding the user-generated image files in the ApplicationDocumentsDirectory
.
Any help or pointers would be appreciated!