Future<ex.Excel> loadExcel(
{@required String sheet, @required String fileName, bool isAsset = false}) async {
File file = File(fileName);
ByteData data;
if (isAsset == true) {
data = await rootBundle.load(fileName);}
else {
print("arrived to read filename $fileName");
data = file.readAsBytesSync().buffer.asByteData();
}
var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
ex.Excel excel = ex.Excel.decodeBytes(bytes, update: true);
return excel;
}
I use rootBundle.load is from the asset and using file if it is from the app directory (through the path)
saving got no issue, using
Future<void> saveExcelSheet(
{@required ex.Excel excel, @required String fileName}) async {
String dir = await getPath();
if (await Permission.storage.request().isGranted) {
excel.encode().then((onValue) async {
File file = File("$dir/$fileName");
file.createSync(recursive: true);
file.writeAsBytesSync(onValue);
});
} else {
print('permission not granted');
}
}
}
what I am facing, is if I initiate the file (copy it to the app directory) and try to read it immediatly, I get file not found error, even though the file exist
I thought it might be that the file needs to be closed, but I could not figure it out how to close the file.,