Skip to content

Instantly share code, notes, and snippets.

Created June 11, 2019 10:49
What would you like to do?
class Asset {
final String assetPath;
final String filename;
Asset(this.assetPath, this.filename);
Future<String> prepare() async {
Directory directory = await getApplicationDocumentsDirectory();
String path = join(directory.path, filename);
bool fileAlreadyExists = await File(path).exists();
if (fileAlreadyExists) {
return path;
// Copy asset into app documents folder so that we can read it
final data = await rootBundle.load(assetPath);
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await File(path).writeAsBytes(bytes);
return path;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment