Skip to content

Instantly share code, notes, and snippets.

@craigomac
Created June 11, 2019 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigomac/a134095b8051ed40910fe17b1700598e to your computer and use it in GitHub Desktop.
Save craigomac/a134095b8051ed40910fe17b1700598e to your computer and use it in GitHub Desktop.
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