From 3fa5ecde8c98a7f34d2d558fa73a53a8951a4e27 Mon Sep 17 00:00:00 2001 From: Amish Garg Date: Thu, 19 Aug 2021 09:36:51 +0530 Subject: [PATCH] bfix loadFileOnDevice --- lib/src/common/file_util.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/src/common/file_util.dart b/lib/src/common/file_util.dart index 8b68f33..5191d67 100644 --- a/lib/src/common/file_util.dart +++ b/lib/src/common/file_util.dart @@ -53,12 +53,15 @@ class FileUtil { return list; } - /// Loads a file from project assets on the device - static Future loadFileOnDevice(String fileAssetLocation) async { + /// Loads a file from project assets at [fileAssetPath] on the device + /// + /// Eg. 'assets/models/my_model.tflite' + static Future 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;