writeToFile function
Implementation
Future<File> writeToFile(ByteData data, String file) async {
final buffer = data.buffer;
Directory? tempDir = await getExternalStorageDirectory();
String? tempPath = tempDir?.path;
var filePath =
tempPath! + '/' + file; // file_01.tmp is dump file, can be anything
return new File(filePath)
.writeAsBytes(buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
}