Created
June 11, 2019 10:49
-
-
Save craigomac/a134095b8051ed40910fe17b1700598e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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