close
close

dart – How to add an asset file accessible via a path and not via the rootbundle (Flutter)

dart – How to add an asset file accessible via a path and not via the rootbundle (Flutter)

I want to be able to have a file assets/someFile.txt and add this to the app so that the file is already on the filesystem, ready to be accessed. I don’t want it to be in the rootbundle (aka asset archive) of Flutter.

// This is what I want to be able to do.
String filePath="${await getApplicationDocumentsDirectory()}/someFile.txt";  
File myFile = File(filePath);

// Not this
// Read the file from the rootbundle
String data = await rootBundle.loadString('assets/someFile.txt');
// create a file on the filesystem and write the data to it.

The reason I want this is because I’m using a library (Objectbox) that requires a file to contain my data. Having a file ready to use right away would be better than having to first read one from the assetbundle, create a file, and then write the data to it.

Is there a way to specify to Flutter that a certain item should just be placed in the app as a file and not included in the rootbundle?