getFileFromAssets function
- String path
Returns the Futurepath
.
Example: getFileFromAssets('assets/file.xlsx')
Implementation
Future<File> getFileFromAssets(String path) async {
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
var file = File("$tempPath/$path");
final data = await PlatformAssetBundle().load(path);
final buffer = data.buffer;
await file.create(recursive: true);
return file.writeAsBytes(buffer.asUint8List(data.offsetInBytes,data.lengthInBytes));
}