getFileFromAssets function

Future<File> getFileFromAssets(
  1. String path
)

Returns the Future of the file at the given path.

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));
}