在我下面的代码的未来是不工作...编辑代码如下################################### ################################################## ################################################## ################################################## ################################################## ################################################## ################################################## ############
void compressImage() async {
print('startin');
final tempDir = await getTemporaryDirectory();
final path = tempDir.path;
int rand = new Math.Random().nextInt(99999999);
Im.Image image = Im.decodeImage(file.readAsBytesSync());
Im.copyResize(image, 500);
// image.format = Im.Image.RGBA;
// Im.Image newim = Im.remapColors(image, alpha: Im.LUMINANCE);
var newim2 = new File('$path/img_$rand.jpg')
..writeAsBytesSync(Im.encodeJpg(image, quality: 85));
setState(() {
file = newim2;
});
print('done');
}
void clearImage() {
setState(() {
file = null;
});
}
void postImage() {
setState(() {
uploading = true;
});
compressImage();
Future<String> upload = uploadImage(file).then((String data) {
Firestore.instance.collection("Advertice").document().setData({
"Content": discription,
"title": title.toUpperCase(),
"url": data,
});
}).then((_) {
setState(() {
file = null;
uploading = false;
});
});
}
}
Future<String> uploadImage(var imageFile) async {
var uuid = new Uuid().v1();
StorageReference ref = FirebaseStorage.instance.ref().child("post_$uuid.jpg");
StorageUploadTask uploadTask = ref.put(imageFile);
Uri URL = (await uploadTask.future).downloadUrl;
return URL.toString();
}