archive
archive copied to clipboard
Last file is added blank always.
Hi thankyou for your great effort :) I have one strange problem. it is always missing last file (png, jpg) in the zip. the last file is added with 0 bytes and not viewable here is my code for the zip method:
List files = [];
var encoder = ZipFileEncoder();
Future _createZip() async {
print('--------------- I Lenght ${files.length}');
encoder.create(_path + '/' + 'new.zip');
// files.forEach((element) {
// encoder.addFile(element);
// });
for (int i = 0; i < files.length; i++) {
encoder.addFile(files[i]);
print('------------ I -----------${files[i]}');
}
encoder.close();
files.clear();
}
/// here is my code for download method from firebase storage.
Future downloadZip(String _index) async {
String iconName = '';
await FirebaseFirestore.instance
.collection('Icons')
.doc('${iconCategory[_value].toString()}')
.collection('Free Icons')
.doc(_index)
.get()
.then((DocumentSnapshot documentSnapshot) => {
print(documentSnapshot.data()['iconName'][0]),
iconName = documentSnapshot.data()['iconName'][0].toString(),
});
StorageReference ref = firebase_storage.FirebaseStorage.instance
.ref()
.child('${iconCategory[_value].toString()}')
.child('$_index'.toString())
.child(iconName);
final String url = await ref.getDownloadURL();
final http.Response downloadData = await http.get(url);
File _tempFile = File('$_path/$iconName');
if (_tempFile.existsSync()) {
await _tempFile.delete();
}
await _tempFile.create();
final StorageFileDownloadTask task = ref.writeToFile(_tempFile);
// final int byteCount = (await task.future).totalByteCount;
var _bodyBytes = downloadData.bodyBytes;
files.add(File.fromUri(_tempFile.uri));
// encoder.addFile(File.fromUri(_tempFile.uri));
// final String name = await ref.getName();
// final String path = await ref.getPath();
// print(_tempFile);
// print(name);
// print(path);
}
and here is my on press method.
onPressed: () async {
// encoder.create(_path + '/' + 'new.zip');
showLoadingDialog(tapDismiss: false);
for (int i = 0; i < selectedIndexes.length; i++) {
await downloadZip(selectedIndexes[i].toString());
}
_createZip();
print('Done Zip');
// encoder.close();
// hideLoadingDialog();
setState(() {
selectedIndexes.clear();
// files.clear();
});
hideLoadingDialog();
}),