Skip to content

Commit

Permalink
bfix loadFileOnDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
am15h committed Aug 19, 2021
1 parent 8827816 commit 3fa5ecd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/src/common/file_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ class FileUtil {
return list;
}

/// Loads a file from project assets on the device
static Future<File> loadFileOnDevice(String fileAssetLocation) async {
/// Loads a file from project assets at [fileAssetPath] on the device
///
/// Eg. 'assets/models/my_model.tflite'
static Future<File> loadFileOnDevice(String fileAssetPath) async {
final appDir = await getTemporaryDirectory();
final appPath = appDir.path;
final fileOnDevice = File('$appPath/$fileAssetLocation');
final rawAssetFile = await rootBundle.load('$fileAssetLocation');
final fileName = fileAssetPath.split('/').last;
final fileOnDevice = File('$appPath/$fileName');
final rawAssetFile = await rootBundle.load('$fileAssetPath');
final rawBytes = rawAssetFile.buffer.asUint8List();
await fileOnDevice.writeAsBytes(rawBytes, flush: true);
return fileOnDevice;
Expand Down

0 comments on commit 3fa5ecd

Please sign in to comment.